mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-14 11:31:33 +08:00
Fix mm.dd.yyyy (time) format
This commit is contained in:
parent
89df0f8c49
commit
7a3c923820
18
parseany.go
18
parseany.go
@ -1143,12 +1143,26 @@ iterRunes:
|
|||||||
return p, p.unknownErr(datestr)
|
return p, p.unknownErr(datestr)
|
||||||
}
|
}
|
||||||
case ' ':
|
case ' ':
|
||||||
|
if p.daylen == 0 && p.molen > 0 && p.yearlen > 0 {
|
||||||
p.daylen = i - p.dayi
|
p.daylen = i - p.dayi
|
||||||
p.stateDate = dateDigitDotDotWs
|
|
||||||
p.stateTime = timeStart
|
|
||||||
if !p.setDay() {
|
if !p.setDay() {
|
||||||
return p, p.unknownErr(datestr)
|
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
|
break iterRunes
|
||||||
case 'T':
|
case 'T':
|
||||||
p.daylen = i - p.dayi
|
p.daylen = i - p.dayi
|
||||||
|
@ -676,6 +676,7 @@ var testInputs = []dateTest{
|
|||||||
{in: "3.31.2014", out: "2014-03-31 00:00:00 +0000 UTC"},
|
{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: "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", 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
|
// mm.dd.yy
|
||||||
{in: "08.21.71", out: "1971-08-21 00:00:00 +0000 UTC"},
|
{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)
|
// 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
|
// Convenience function for debugging a particular broken test case
|
||||||
func TestDebug(t *testing.T) {
|
func TestDebug(t *testing.T) {
|
||||||
ts := MustParse("03:08:2012 18:31:59+00:00", PreferMonthFirst(false))
|
ts := MustParse("03.31.2014 10:11:59 MST-0700", PreferMonthFirst(true))
|
||||||
assert.Equal(t, "2012-08-03 18:31:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2014-03-31 17:11:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user