1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-02-01 01:37:12 +00:00

Interpret a Date in the Gelf timestamp field as UTC midnight

This commit is contained in:
Holger Just 2018-06-15 00:12:51 +02:00
parent a70b859a53
commit a807f99af5
2 changed files with 4 additions and 2 deletions

View File

@ -134,8 +134,10 @@ module Rackstash
def gelf_timestamp(timestamp)
time = case timestamp
when Time, DateTime, Date
when Time, DateTime
timestamp.to_time
when Date
Time.new(timestamp.year, timestamp.month, timestamp.day, 0, 0, 0, 0)
when String
Time.iso8601(timestamp) rescue Time.now.utc
when Integer, Float

View File

@ -55,7 +55,7 @@ RSpec.describe Rackstash::Encoder::GELF do
it 'formats a Date' do
event = { '@timestamp' => Date.new(2016, 10, 17) }
expect(encoder.encode(event)).to include '"timestamp":1476655200.0'
expect(encoder.encode(event)).to include '"timestamp":1476662400.0'
end
it 'formats a String' do