Skip to content

Commit

Permalink
Correctly parse timestamps from 1970
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirianni committed Feb 25, 2022
1 parent c100556 commit 61a965c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion operator/helper/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ var subsecToNs = map[string]int64{"s.ms": 1e6, "s.us": 1e3, "s.ns": 1}
// setTimestampYear sets the year of a timestamp to the current year.
// This is needed because year is missing from some time formats, such as rfc3164.
func setTimestampYear(t time.Time) time.Time {
if t.Year() > 1970 {
if t.Year() > 0 {
return t
}
n := now()
Expand Down
7 changes: 7 additions & 0 deletions operator/helper/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ func TestTimeParser(t *testing.T) {
strptimeLayout: "%Y-%m-%dT%H:%M:%S.%LZ",
location: hst.String(),
},
{
name: "1970",
sample: "1970-12-16T21:43:28.391Z",
expected: time.Date(1970, 12, 16, 21, 43, 28, 391*1000*1000, time.UTC),
gotimeLayout: "2006-01-02T15:04:05.999Z",
strptimeLayout: "%Y-%m-%dT%H:%M:%S.%LZ",
},
}

rootField := entry.NewRecordField()
Expand Down

0 comments on commit 61a965c

Please sign in to comment.