Method: LogStash::Time.to_iso8601
- Defined in:
- lib/logstash/time.rb
.to_iso8601(obj) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/logstash/time.rb', line 21 def self.to_iso8601(obj) if obj.is_a?(DateTime) tz = obj.offset == 0 ? "Z" : obj.strftime("%z") # DateTime#sec_fraction is fractional seconds "of a day" sec_fraction = (obj.sec_fraction.to_f * 86400 * 1000000) return "%s.%06d%s" % [obj.strftime(ISO8601), sec_fraction, tz] else raise "Can't convert object of type #{obj.class} (#{obj}) to iso8601." end end |