From dd780a39a397cb278b5b5f92045def506cd4b230 Mon Sep 17 00:00:00 2001 From: Philippe Horne Date: Wed, 19 Jun 2019 13:28:39 -0400 Subject: [PATCH 1/2] Added fix to parse dates of the format 28-Feb-18 and 28-Feb-2018. --- parseany.go | 22 ++++++++++++++++++++++ parseany_test.go | 3 +++ 2 files changed, 25 insertions(+) diff --git a/parseany.go b/parseany.go index 6ac5a86..5e66aa6 100644 --- a/parseany.go +++ b/parseany.go @@ -1551,6 +1551,28 @@ iterRunes: // 13-Feb-03 ambiguous // 28-Feb-03 ambiguous // 29-Jun-2016 + length := len(datestr) - (p.moi + p.molen + 1) + 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() + } + return p, nil case dateDigitDot: diff --git a/parseany_test.go b/parseany_test.go index c278ec9..23d93fc 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -213,6 +213,9 @@ var testInputs = []dateTest{ {in: "2014-04-02", out: "2014-04-02 00:00:00 +0000 UTC"}, {in: "2014-03-31", out: "2014-03-31 00:00:00 +0000 UTC"}, {in: "2014-4-2", out: "2014-04-02 00:00:00 +0000 UTC"}, + // dd-mmm-yy + {in: "28-Feb-02", out: "2002-02-28 00:00:00 +0000 UTC"}, + {in: "15-Jan-18", out: "2018-01-15 00:00:00 +0000 UTC"}, // yyyy-mm {in: "2014-04", out: "2014-04-01 00:00:00 +0000 UTC"}, // yyyy-mm-dd hh:mm:ss AM From 0f774641240007584c5711b9b22facbc52bc2bb9 Mon Sep 17 00:00:00 2001 From: Philippe Horne Date: Wed, 19 Jun 2019 15:53:12 -0400 Subject: [PATCH 2/2] Added a test to cover the 4 year date when dealing with dates of the type 28-Feb-2018. --- parseany_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/parseany_test.go b/parseany_test.go index 23d93fc..2d92f43 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -216,6 +216,7 @@ var testInputs = []dateTest{ // dd-mmm-yy {in: "28-Feb-02", out: "2002-02-28 00:00:00 +0000 UTC"}, {in: "15-Jan-18", out: "2018-01-15 00:00:00 +0000 UTC"}, + {in: "15-Jan-2017", out: "2017-01-15 00:00:00 +0000 UTC"}, // yyyy-mm {in: "2014-04", out: "2014-04-01 00:00:00 +0000 UTC"}, // yyyy-mm-dd hh:mm:ss AM