mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
- Add time wrapper for iso8601 support
This commit is contained in:
parent
d9c8381754
commit
1575edcdb1
1 changed files with 19 additions and 0 deletions
19
lib/time.rb
Normal file
19
lib/time.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue