From 0b3cf7db1a36ebaaaeccfc087e8e57cd7ba1ef6b Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 2 Jul 2015 16:35:58 +0200 Subject: [PATCH] Adding eamon special timestamp format --- utils/coreutils.go | 3 +++ utils/utils_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/utils/coreutils.go b/utils/coreutils.go index 1788aeab4..983c7193c 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -137,6 +137,7 @@ func ParseTimeDetectLayout(tmStr string) (time.Time, error) { unixTimestampRule := regexp.MustCompile(`^\d{10}$`) oneLineTimestampRule := regexp.MustCompile(`^\d{14}$`) oneSpaceTimestampRule := regexp.MustCompile(`^\d{2}\.\d{2}.\d{4}\s{1}\d{2}:\d{2}:\d{2}$`) + eamonTimestampRule := regexp.MustCompile(`^\d{2}/\d{2}/\d{4}\s{1}\d{2}:\d{2}:\d{2}$`) switch { case rfc3339Rule.MatchString(tmStr): return time.Parse(time.RFC3339, tmStr) @@ -162,6 +163,8 @@ func ParseTimeDetectLayout(tmStr string) (time.Time, error) { return time.Parse("20060102150405", tmStr) case oneSpaceTimestampRule.MatchString(tmStr): return time.Parse("02.01.2006 15:04:05", tmStr) + case eamonTimestampRule.MatchString(tmStr): + return time.Parse("02/01/2006 15:04:05", tmStr) case tmStr == "*now": return time.Now(), nil } diff --git a/utils/utils_test.go b/utils/utils_test.go index 4f2b2a580..8ea8cd6ba 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -224,6 +224,14 @@ func TestParseTimeDetectLayout(t *testing.T) { } else if time.Now().Sub(nowTm) > time.Duration(1)*time.Millisecond { t.Errorf("Unexpected time parsed: %v", nowTm) } + eamonTmStr := "31/05/2015 14:46:00" + eamonTmS, err := ParseTimeDetectLayout(eamonTmStr) + expectedTime = time.Date(2015, 5, 31, 14, 46, 0, 0, time.UTC) + if err != nil { + t.Error(err) + } else if !eamonTmS.Equal(expectedTime) { + t.Errorf("Unexpected time parsed: %v, expecting: %v", eamonTmS, expectedTime) + } } func TestParseDateUnix(t *testing.T) {