Class: Time
- Defined in:
- lib/gorillib/datetime/flat.rb,
lib/gorillib/serialization.rb,
lib/gorillib/datetime/parse.rb
Constant Summary collapse
- FLAT_FORMAT =
strftime() format to flatten a date
"%Y%m%d%H%M%S"
Class Method Summary collapse
-
.parse_safely(dt) ⇒ Object
Parses the time but never fails.
Instance Method Summary collapse
Class Method Details
.parse_safely(dt) ⇒ Object
Parses the time but never fails. Return value is always in the UTC time zone.
A flattened datetime ā a 14-digit YYYYmmddHHMMMSS ā is fixed to the UTC time zone by parsing it as YYYYmmddHHMMMSSZ <- āZā at end
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gorillib/datetime/parse.rb', line 11 def self.parse_safely dt return nil if dt.nil? || (dt.respond_to?(:empty) && dt.empty?) begin case when dt.is_a?(Time) then dt.utc when (dt.to_s =~ /\A\d{14}\z/) then parse(dt.to_s+'Z', true) else parse(dt.to_s, true).utc end rescue StandardError => e Log.debug e end end |
Instance Method Details
#to_flat ⇒ Object
Flatten
8 9 10 |
# File 'lib/gorillib/datetime/flat.rb', line 8 def to_flat utc.strftime(FLAT_FORMAT) end |
#to_wire(options = {}) ⇒ Object
45 46 47 |
# File 'lib/gorillib/serialization.rb', line 45 def to_wire(={}) self.iso8601 end |