mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 11:16:12 +08:00
Support times after yyyy.mm.dd dates
Fix for this bug mentioned in https://github.com/araddon/dateparse/pull/134 Also, the other cases mentioned in this PR are not valid formats, so add them to the TestParseErrors test, to document that this is expected.
This commit is contained in:
parent
23869f345e
commit
cc63421875
74
parseany.go
74
parseany.go
@ -69,18 +69,21 @@ const (
|
|||||||
dateDigitDashDigitDash
|
dateDigitDashDigitDash
|
||||||
dateDigitDot
|
dateDigitDot
|
||||||
dateDigitDotDot
|
dateDigitDotDot
|
||||||
|
dateDigitDotDotWs
|
||||||
|
dateDigitDotDotT
|
||||||
|
dateDigitDotDotOffset
|
||||||
dateDigitSlash
|
dateDigitSlash
|
||||||
dateDigitYearSlash
|
dateDigitYearSlash
|
||||||
dateDigitSlashAlpha // 18
|
dateDigitSlashAlpha // 21
|
||||||
dateDigitColon
|
dateDigitColon
|
||||||
dateDigitChineseYear
|
dateDigitChineseYear
|
||||||
dateDigitChineseYearWs
|
dateDigitChineseYearWs
|
||||||
dateDigitWs
|
dateDigitWs
|
||||||
dateDigitWsMoYear // 23
|
dateDigitWsMoYear // 26
|
||||||
dateAlpha
|
dateAlpha
|
||||||
dateAlphaWs
|
dateAlphaWs
|
||||||
dateAlphaWsDigit
|
dateAlphaWsDigit
|
||||||
dateAlphaWsDigitMore // 27
|
dateAlphaWsDigitMore // 30
|
||||||
dateAlphaWsDigitMoreWs
|
dateAlphaWsDigitMoreWs
|
||||||
dateAlphaWsDigitMoreWsYear
|
dateAlphaWsDigitMoreWsYear
|
||||||
dateAlphaWsMonth
|
dateAlphaWsMonth
|
||||||
@ -90,7 +93,7 @@ const (
|
|||||||
dateAlphaWsMore
|
dateAlphaWsMore
|
||||||
dateAlphaWsAtTime
|
dateAlphaWsAtTime
|
||||||
dateAlphaWsAlpha
|
dateAlphaWsAlpha
|
||||||
dateAlphaWsAlphaYearmaybe // 37
|
dateAlphaWsAlphaYearmaybe // 40
|
||||||
dateAlphaPeriodWsDigit
|
dateAlphaPeriodWsDigit
|
||||||
dateAlphaSlash
|
dateAlphaSlash
|
||||||
dateAlphaSlashDigit
|
dateAlphaSlashDigit
|
||||||
@ -924,8 +927,52 @@ iterRunes:
|
|||||||
p.stateDate = dateDigitDotDot
|
p.stateDate = dateDigitDotDot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case dateDigitDotDot:
|
case dateDigitDotDot:
|
||||||
// iterate all the way through
|
// dateYearDashDashT
|
||||||
|
// 2006.01.02T15:04:05Z07:00
|
||||||
|
// dateYearDashDashWs
|
||||||
|
// 2013.04.01 22:43:22
|
||||||
|
// dateYearDashDashOffset
|
||||||
|
// 2020.07.20+00:00
|
||||||
|
switch r {
|
||||||
|
case '+', '-':
|
||||||
|
p.offseti = i
|
||||||
|
p.daylen = i - p.dayi
|
||||||
|
p.stateDate = dateDigitDotDotOffset
|
||||||
|
if !p.setDay() {
|
||||||
|
return p, unknownErr(datestr)
|
||||||
|
}
|
||||||
|
case ' ':
|
||||||
|
p.daylen = i - p.dayi
|
||||||
|
p.stateDate = dateDigitDotDotWs
|
||||||
|
p.stateTime = timeStart
|
||||||
|
if !p.setDay() {
|
||||||
|
return p, unknownErr(datestr)
|
||||||
|
}
|
||||||
|
break iterRunes
|
||||||
|
case 'T':
|
||||||
|
p.daylen = i - p.dayi
|
||||||
|
p.stateDate = dateDigitDotDotT
|
||||||
|
p.stateTime = timeStart
|
||||||
|
if !p.setDay() {
|
||||||
|
return p, unknownErr(datestr)
|
||||||
|
}
|
||||||
|
break iterRunes
|
||||||
|
}
|
||||||
|
|
||||||
|
case dateDigitDotDotT:
|
||||||
|
// dateYearDashDashT
|
||||||
|
// 2006-01-02T15:04:05Z07:00
|
||||||
|
// 2020-08-17T17:00:00:000+0100
|
||||||
|
|
||||||
|
case dateDigitDotDotOffset:
|
||||||
|
// 2020-07-20+00:00
|
||||||
|
switch r {
|
||||||
|
case ':':
|
||||||
|
p.set(p.offseti, "-07:00")
|
||||||
|
}
|
||||||
|
|
||||||
case dateAlpha:
|
case dateAlpha:
|
||||||
// dateAlphaWS
|
// dateAlphaWS
|
||||||
// Mon Jan _2 15:04:05 2006
|
// Mon Jan _2 15:04:05 2006
|
||||||
@ -2177,6 +2224,23 @@ iterRunes:
|
|||||||
// 2018.09.30
|
// 2018.09.30
|
||||||
return p, nil
|
return p, nil
|
||||||
|
|
||||||
|
case dateDigitDotDotWs:
|
||||||
|
// 2013.04.01
|
||||||
|
return p, nil
|
||||||
|
|
||||||
|
case dateDigitDotDotT:
|
||||||
|
return p, nil
|
||||||
|
|
||||||
|
case dateDigitDotDotOffset:
|
||||||
|
// 2020.07.20+00:00
|
||||||
|
switch len(p.datestr) - p.offseti {
|
||||||
|
case 5:
|
||||||
|
p.set(p.offseti, "-0700")
|
||||||
|
case 6:
|
||||||
|
p.set(p.offseti, "-07:00")
|
||||||
|
}
|
||||||
|
return p, nil
|
||||||
|
|
||||||
case dateDigitWsMoYear:
|
case dateDigitWsMoYear:
|
||||||
// 2 Jan 2018
|
// 2 Jan 2018
|
||||||
// 2 Jan 18
|
// 2 Jan 18
|
||||||
|
@ -647,6 +647,16 @@ var testInputs = []dateTest{
|
|||||||
// https://github.com/araddon/dateparse/issues/158
|
// https://github.com/araddon/dateparse/issues/158
|
||||||
{in: "Mon, 1 Dec 2008 14:48:22 GMT-07:00", out: "2008-12-01 21:48:22 +0000 UTC"},
|
{in: "Mon, 1 Dec 2008 14:48:22 GMT-07:00", out: "2008-12-01 21:48:22 +0000 UTC"},
|
||||||
{in: "Mon, 1 Dec 2008 14:48:22 UTC-07:00", out: "2008-12-01 21:48:22 +0000 UTC"},
|
{in: "Mon, 1 Dec 2008 14:48:22 UTC-07:00", out: "2008-12-01 21:48:22 +0000 UTC"},
|
||||||
|
|
||||||
|
// Fixes for bugs mentioned in https://github.com/araddon/dateparse/pull/134
|
||||||
|
{in: "2014.02.13", out: "2014-02-13 00:00:00 +0000 UTC"},
|
||||||
|
{in: "2014-02-13 00:00:00", out: "2014-02-13 00:00:00 +0000 UTC"},
|
||||||
|
{in: "2014.02.13 00:00:00", out: "2014-02-13 00:00:00 +0000 UTC"},
|
||||||
|
{in: "2014.02.13 08:33:44", out: "2014-02-13 08:33:44 +0000 UTC"},
|
||||||
|
{in: "2014.02.13T08:33:44", out: "2014-02-13 08:33:44 +0000 UTC"},
|
||||||
|
{in: "2014.02.13T08:33:44.555", out: "2014-02-13 08:33:44.555 +0000 UTC"},
|
||||||
|
{in: "2014.02.13T08:33:44.555 PM -0700 MST", out: "2014-02-14 03:33:44.555 +0000 UTC", zname: "MST"},
|
||||||
|
{in: "2014.02.13-0200", out: "2014-02-13 02:00:00 +0000 UTC"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
@ -802,6 +812,10 @@ var testParseErrors = []dateTest{
|
|||||||
{in: "2018-09-30 08:09:13.123AM am", err: true},
|
{in: "2018-09-30 08:09:13.123AM am", err: true},
|
||||||
{in: "2018-09-30 08:09:13.123 am AM", err: true},
|
{in: "2018-09-30 08:09:13.123 am AM", err: true},
|
||||||
{in: "2018-09-30 08:09:13.123 AMDT am", err: true},
|
{in: "2018-09-30 08:09:13.123 AMDT am", err: true},
|
||||||
|
// https://github.com/araddon/dateparse/pull/134
|
||||||
|
{in: "2014-02-13 00:00:00 utc", err: true}, // lowercase timezones are not valid
|
||||||
|
{in: "2014-02-13t00:00:00.0z", err: true}, // lowercase 't' separator is not supported
|
||||||
|
{in: "2014-02-13T00:00:00.0z", err: true}, // lowercase 'z' zulu timezone indicator not a valid format
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseErrors(t *testing.T) {
|
func TestParseErrors(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user