mirror of
https://github.com/araddon/dateparse.git
synced 2024-12-05 05:30:13 +08:00
Merge pull request #87 from phorne-uncharted/dash-year-day
Added fix for dates split with dashes
This commit is contained in:
commit
0fb0a474d1
22
parseany.go
22
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:
|
||||
|
@ -213,6 +213,10 @@ 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"},
|
||||
{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
|
||||
|
Loading…
Reference in New Issue
Block a user