From 2cbb9d374c4ca56795eb1273f39dcf640fe5bef7 Mon Sep 17 00:00:00 2001 From: liushaobo Date: Wed, 10 Mar 2021 11:07:49 +0800 Subject: [PATCH] rabbitmq log datetime support --- parseany.go | 30 ++++++++++++++++++++++++++++++ parseany_test.go | 2 ++ 2 files changed, 32 insertions(+) diff --git a/parseany.go b/parseany.go index b97e54e..774ef19 100644 --- a/parseany.go +++ b/parseany.go @@ -491,6 +491,35 @@ iterRunes: } p.stateTime = timeStart break iterRunes + case ':': + p.link++ + if p.link == 2 { + // we need to find if this was 4 digits, aka year + // or 2 digits which makes it ambiguous year/day + length := i - (p.moi + p.molen + 2) + if length == 4 { + p.yearlen = 4 + p.set(p.yeari, "2006") + // We now also know that part1 was the day + p.dayi = 0 + p.daylen = p.part1Len + p.setDay() + } else if length == 2 { + // We have no idea if this is + // yy-mon-dd OR dd-mon-yy + // + // We are going to ASSUME (bad, bad) that it is dd-mon-yy which is a horible assumption + p.ambiguousMD = true + p.yearlen = 2 + p.set(p.yeari, "06") + // We now also know that part1 was the day + p.dayi = 0 + p.daylen = p.part1Len + p.setDay() + } + p.stateTime = timeStart + break iterRunes + } } case dateDigitSlash: @@ -1839,6 +1868,7 @@ type parser struct { datestr string fullMonth string skip int + link int extra int part1Len int yeari int diff --git a/parseany_test.go b/parseany_test.go index 8e19076..3003514 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -532,6 +532,8 @@ var testParseFormat = []dateTest{ {in: "2009-08-12T22:15:09-0700", out: "2006-01-02T15:04:05-0700"}, // yyyy-mm-ddThh:mm:ssZ {in: "2009-08-12T22:15Z", out: "2006-01-02T15:04Z"}, + + {in: "8-Mar-2018::14:09:27", out: "2-Jan-2006::15:04:05"}, } func TestParseLayout(t *testing.T) {