Fix mm.dd.yyyy (time) format

This commit is contained in:
Klondike Dragon 2023-12-18 23:14:08 -07:00
parent 89df0f8c49
commit 7a3c923820
2 changed files with 19 additions and 4 deletions

View File

@ -1143,12 +1143,26 @@ iterRunes:
return p, p.unknownErr(datestr)
}
case ' ':
if p.daylen == 0 && p.molen > 0 && p.yearlen > 0 {
p.daylen = i - p.dayi
p.stateDate = dateDigitDotDotWs
p.stateTime = timeStart
if !p.setDay() {
return p, p.unknownErr(datestr)
}
} else if p.molen == 0 && p.daylen > 0 && p.yearlen > 0 {
p.molen = i - p.moi
if !p.setMonth() {
return p, p.unknownErr(datestr)
}
} else if p.yearlen == 0 && p.daylen > 0 && p.molen > 0 {
p.yearlen = i - p.yeari
if !p.setYear() {
return p, p.unknownErr(datestr)
}
} else {
return p, p.unknownErr(datestr)
}
p.stateDate = dateDigitDotDotWs
p.stateTime = timeStart
break iterRunes
case 'T':
p.daylen = i - p.dayi

View File

@ -676,6 +676,7 @@ var testInputs = []dateTest{
{in: "3.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
{in: "3.3.2014", out: "2014-03-03 00:00:00 +0000 UTC"},
{in: "03.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
{in: "03.31.2014 10:11:59 MST", out: "2014-03-31 10:11:59 +0000 UTC", zname: "MST"},
// mm.dd.yy
{in: "08.21.71", out: "1971-08-21 00:00:00 +0000 UTC"},
// dd.mm.yyyy (see https://github.com/araddon/dateparse/issues/129 and https://github.com/araddon/dateparse/issues/28 and https://github.com/araddon/dateparse/pull/133)
@ -1198,6 +1199,6 @@ func TestRetryAmbiguousDateWithSwap(t *testing.T) {
// Convenience function for debugging a particular broken test case
func TestDebug(t *testing.T) {
ts := MustParse("03:08:2012 18:31:59+00:00", PreferMonthFirst(false))
assert.Equal(t, "2012-08-03 18:31:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts := MustParse("03.31.2014 10:11:59 MST-0700", PreferMonthFirst(true))
assert.Equal(t, "2014-03-31 17:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
}