Skip to content

Commit 5260cf1

Browse files
authored
fix parsing of noncompliant RFC3339 timestamps missing only a timezone (#3346)
1 parent 172d6c6 commit 5260cf1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

pkg/parser/enrich_date.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func GenDateParse(date string) (string, time.Time) {
4444
"2006-01-02 15:04",
4545
"2006/01/02 15:04:05",
4646
"2006-01-02 15:04:05",
47+
"2006-01-02T15:04:05",
4748
}
4849
)
4950

pkg/parser/enrich_date_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,38 @@ func TestDateParse(t *testing.T) {
4040
},
4141
expected: "2011-12-17T08:17:43Z",
4242
},
43+
{
44+
name: "ISO 8601, no timezone",
45+
evt: types.Event{
46+
StrTime: "2024-11-26T20:13:32",
47+
StrTimeFormat: "",
48+
},
49+
expected: "2024-11-26T20:13:32Z",
50+
},
51+
{
52+
name: "ISO 8601, no timezone, milliseconds",
53+
evt: types.Event{
54+
StrTime: "2024-11-26T20:13:32.123",
55+
StrTimeFormat: "",
56+
},
57+
expected: "2024-11-26T20:13:32.123Z",
58+
},
59+
{
60+
name: "ISO 8601, no timezone, microseconds",
61+
evt: types.Event{
62+
StrTime: "2024-11-26T20:13:32.123456",
63+
StrTimeFormat: "",
64+
},
65+
expected: "2024-11-26T20:13:32.123456Z",
66+
},
67+
{
68+
name: "ISO 8601, no timezone, nanoseconds",
69+
evt: types.Event{
70+
StrTime: "2024-11-26T20:13:32.123456789",
71+
StrTimeFormat: "",
72+
},
73+
expected: "2024-11-26T20:13:32.123456789Z",
74+
},
4375
}
4476

4577
logger := log.WithField("test", "test")

0 commit comments

Comments
 (0)