- Add time wrapper for iso8601 support

This commit is contained in:
Jordan Sissel 2010-10-17 07:27:24 +00:00
parent d9c8381754
commit 1575edcdb1

19
lib/time.rb Normal file
View file

@ -0,0 +1,19 @@
# Provide our own Time wrapper for ISO8601 support
# Example:
# >> LogStash::Time.now.to_iso8601
# => "2010-10-17 00:25:24.619014-0700"
#
# >> LogStash::Time.now.utc.to_iso8601
# => "2010-10-17 07:25:26.788704Z"
module LogStash; class Time < ::Time
# Return a string that is this time in ISO8601 format.
def to_iso8601
if self.utc?
tz = "Z"
else
tz = self.strftime("%z")
end
return self.strftime("%Y-%m-%d %H:%M:%S") + ".#{self.tv_usec}#{tz}"
end
end; end # class LogStash::Time