Skip to content

Commit 0fb0a47

Browse files
authored
Merge pull request #87 from phorne-uncharted/dash-year-day
Added fix for dates split with dashes
2 parents d2ba703 + 0f77464 commit 0fb0a47

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

parseany.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,28 @@ iterRunes:
15511551
// 13-Feb-03 ambiguous
15521552
// 28-Feb-03 ambiguous
15531553
// 29-Jun-2016
1554+
length := len(datestr) - (p.moi + p.molen + 1)
1555+
if length == 4 {
1556+
p.yearlen = 4
1557+
p.set(p.yeari, "2006")
1558+
// We now also know that part1 was the day
1559+
p.dayi = 0
1560+
p.daylen = p.part1Len
1561+
p.setDay()
1562+
} else if length == 2 {
1563+
// We have no idea if this is
1564+
// yy-mon-dd OR dd-mon-yy
1565+
//
1566+
// We are going to ASSUME (bad, bad) that it is dd-mon-yy which is a horible assumption
1567+
p.ambiguousMD = true
1568+
p.yearlen = 2
1569+
p.set(p.yeari, "06")
1570+
// We now also know that part1 was the day
1571+
p.dayi = 0
1572+
p.daylen = p.part1Len
1573+
p.setDay()
1574+
}
1575+
15541576
return p, nil
15551577

15561578
case dateDigitDot:

parseany_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ var testInputs = []dateTest{
213213
{in: "2014-04-02", out: "2014-04-02 00:00:00 +0000 UTC"},
214214
{in: "2014-03-31", out: "2014-03-31 00:00:00 +0000 UTC"},
215215
{in: "2014-4-2", out: "2014-04-02 00:00:00 +0000 UTC"},
216+
// dd-mmm-yy
217+
{in: "28-Feb-02", out: "2002-02-28 00:00:00 +0000 UTC"},
218+
{in: "15-Jan-18", out: "2018-01-15 00:00:00 +0000 UTC"},
219+
{in: "15-Jan-2017", out: "2017-01-15 00:00:00 +0000 UTC"},
216220
// yyyy-mm
217221
{in: "2014-04", out: "2014-04-01 00:00:00 +0000 UTC"},
218222
// yyyy-mm-dd hh:mm:ss AM

0 commit comments

Comments
 (0)