mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 03:41:55 +08:00
New date format 2020-07-20+00:00 fixes #110
This commit is contained in:
parent
36fa6fb41d
commit
0eec95c9db
@ -154,6 +154,8 @@ var examples = []string{
|
|||||||
"2014-04",
|
"2014-04",
|
||||||
"2014",
|
"2014",
|
||||||
"2014-05-11 08:20:13,787",
|
"2014-05-11 08:20:13,787",
|
||||||
|
// yyyy-mm-dd-07:00
|
||||||
|
"2020-07-20+08:00",
|
||||||
// mm.dd.yy
|
// mm.dd.yy
|
||||||
"3.31.2014",
|
"3.31.2014",
|
||||||
"03.31.2014",
|
"03.31.2014",
|
||||||
@ -302,6 +304,7 @@ func main() {
|
|||||||
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
|
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
|
||||||
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
|
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
|
||||||
| 2014-05-11 08:20:13,787 | 2014-05-11 08:20:13.787 +0000 UTC |
|
| 2014-05-11 08:20:13,787 | 2014-05-11 08:20:13.787 +0000 UTC |
|
||||||
|
| 2020-07-20+08:00 | 2020-07-20 00:00:00 +0800 +0800 |
|
||||||
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
||||||
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
||||||
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
|
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
|
||||||
|
@ -111,6 +111,8 @@ var examples = []string{
|
|||||||
"2014-04",
|
"2014-04",
|
||||||
"2014",
|
"2014",
|
||||||
"2014-05-11 08:20:13,787",
|
"2014-05-11 08:20:13,787",
|
||||||
|
// yyyy-mm-dd-07:00
|
||||||
|
"2020-07-20+08:00",
|
||||||
// mm.dd.yy
|
// mm.dd.yy
|
||||||
"3.31.2014",
|
"3.31.2014",
|
||||||
"03.31.2014",
|
"03.31.2014",
|
||||||
@ -259,6 +261,7 @@ func main() {
|
|||||||
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
|
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
|
||||||
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
|
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
|
||||||
| 2014-05-11 08:20:13,787 | 2014-05-11 08:20:13.787 +0000 UTC |
|
| 2014-05-11 08:20:13,787 | 2014-05-11 08:20:13.787 +0000 UTC |
|
||||||
|
| 2020-07-20+08:00 | 2020-07-20 00:00:00 +0800 +0800 |
|
||||||
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
||||||
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
|
||||||
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
|
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
|
||||||
|
49
parseany.go
49
parseany.go
@ -61,35 +61,36 @@ const (
|
|||||||
dateYearDashDash
|
dateYearDashDash
|
||||||
dateYearDashDashWs // 5
|
dateYearDashDashWs // 5
|
||||||
dateYearDashDashT
|
dateYearDashDashT
|
||||||
|
dateYearDashDashOffset
|
||||||
dateDigitDash
|
dateDigitDash
|
||||||
dateDigitDashAlpha
|
dateDigitDashAlpha
|
||||||
dateDigitDashAlphaDash
|
dateDigitDashAlphaDash // 10
|
||||||
dateDigitDot // 10
|
dateDigitDot
|
||||||
dateDigitDotDot
|
dateDigitDotDot
|
||||||
dateDigitSlash
|
dateDigitSlash
|
||||||
dateDigitYearSlash
|
dateDigitYearSlash
|
||||||
dateDigitSlashAlpha
|
dateDigitSlashAlpha // 15
|
||||||
dateDigitColon // 15
|
dateDigitColon
|
||||||
dateDigitChineseYear
|
dateDigitChineseYear
|
||||||
dateDigitChineseYearWs
|
dateDigitChineseYearWs
|
||||||
dateDigitWs
|
dateDigitWs
|
||||||
dateDigitWsMoYear
|
dateDigitWsMoYear // 20
|
||||||
dateDigitWsMolong // 20
|
dateDigitWsMolong
|
||||||
dateAlpha
|
dateAlpha
|
||||||
dateAlphaWs
|
dateAlphaWs
|
||||||
dateAlphaWsDigit
|
dateAlphaWsDigit
|
||||||
dateAlphaWsDigitMore
|
dateAlphaWsDigitMore // 25
|
||||||
dateAlphaWsDigitMoreWs // 25
|
dateAlphaWsDigitMoreWs
|
||||||
dateAlphaWsDigitMoreWsYear
|
dateAlphaWsDigitMoreWsYear
|
||||||
dateAlphaWsMonth
|
dateAlphaWsMonth
|
||||||
dateAlphaWsDigitYearmaybe
|
dateAlphaWsDigitYearmaybe
|
||||||
dateAlphaWsMonthMore
|
dateAlphaWsMonthMore
|
||||||
dateAlphaWsMonthSuffix // 30
|
dateAlphaWsMonthSuffix
|
||||||
dateAlphaWsMore
|
dateAlphaWsMore
|
||||||
dateAlphaWsAtTime
|
dateAlphaWsAtTime
|
||||||
dateAlphaWsAlpha
|
dateAlphaWsAlpha
|
||||||
dateAlphaWsAlphaYearmaybe
|
dateAlphaWsAlphaYearmaybe // 35
|
||||||
dateAlphaPeriodWsDigit // 35
|
dateAlphaPeriodWsDigit
|
||||||
dateWeekdayComma
|
dateWeekdayComma
|
||||||
dateWeekdayAbbrevComma
|
dateWeekdayAbbrevComma
|
||||||
)
|
)
|
||||||
@ -434,7 +435,14 @@ iterRunes:
|
|||||||
// 2006-01-02T15:04:05Z07:00
|
// 2006-01-02T15:04:05Z07:00
|
||||||
// dateYearDashDashWs
|
// dateYearDashDashWs
|
||||||
// 2013-04-01 22:43:22
|
// 2013-04-01 22:43:22
|
||||||
|
// dateYearDashDashOffset
|
||||||
|
// 2020-07-20+00:00
|
||||||
switch r {
|
switch r {
|
||||||
|
case '+', '-':
|
||||||
|
p.offseti = i
|
||||||
|
p.daylen = i - p.dayi
|
||||||
|
p.stateDate = dateYearDashDashOffset
|
||||||
|
p.setDay()
|
||||||
case ' ':
|
case ' ':
|
||||||
p.daylen = i - p.dayi
|
p.daylen = i - p.dayi
|
||||||
p.stateDate = dateYearDashDashWs
|
p.stateDate = dateYearDashDashWs
|
||||||
@ -454,6 +462,15 @@ iterRunes:
|
|||||||
// 2006-01-02T15:04:05Z07:00
|
// 2006-01-02T15:04:05Z07:00
|
||||||
// 2020-08-17T17:00:00:000+0100
|
// 2020-08-17T17:00:00:000+0100
|
||||||
|
|
||||||
|
case dateYearDashDashOffset:
|
||||||
|
// 2020-07-20+00:00
|
||||||
|
switch r {
|
||||||
|
case ':':
|
||||||
|
p.set(p.offseti, "-07:00")
|
||||||
|
// case ' ':
|
||||||
|
// return nil, unknownErr(datestr)
|
||||||
|
}
|
||||||
|
|
||||||
case dateYearDashAlphaDash:
|
case dateYearDashAlphaDash:
|
||||||
// 2013-Feb-03
|
// 2013-Feb-03
|
||||||
switch r {
|
switch r {
|
||||||
@ -1777,6 +1794,16 @@ iterRunes:
|
|||||||
// 2006-01-2
|
// 2006-01-2
|
||||||
return p, nil
|
return p, nil
|
||||||
|
|
||||||
|
case dateYearDashDashOffset:
|
||||||
|
/// 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 dateYearDashAlphaDash:
|
case dateYearDashAlphaDash:
|
||||||
// 2013-Feb-03
|
// 2013-Feb-03
|
||||||
// 2013-Feb-3
|
// 2013-Feb-3
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
func TestOne(t *testing.T) {
|
func TestOne(t *testing.T) {
|
||||||
time.Local = time.UTC
|
time.Local = time.UTC
|
||||||
var ts time.Time
|
var ts time.Time
|
||||||
ts = MustParse("Thu, 17 Dec 2020 15:39:13 GMT")
|
ts = MustParse("2020-07-20+08:00")
|
||||||
assert.Equal(t, "2020-12-17 15:39:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2020-07-19 16:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateTest struct {
|
type dateTest struct {
|
||||||
@ -236,6 +236,9 @@ var testInputs = []dateTest{
|
|||||||
{in: "2014-04-02", out: "2014-04-02 00:00:00 +0000 UTC"},
|
{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-03-31", out: "2014-03-31 00:00:00 +0000 UTC"},
|
||||||
{in: "2014-4-2", out: "2014-04-02 00:00:00 +0000 UTC"},
|
{in: "2014-4-2", out: "2014-04-02 00:00:00 +0000 UTC"},
|
||||||
|
// yyyy-mm-dd-07:00
|
||||||
|
{in: "2020-07-20+08:00", out: "2020-07-19 16:00:00 +0000 UTC"},
|
||||||
|
{in: "2020-07-20+0800", out: "2020-07-19 16:00:00 +0000 UTC"},
|
||||||
// dd-mmm-yy
|
// dd-mmm-yy
|
||||||
{in: "28-Feb-02", out: "2002-02-28 00:00:00 +0000 UTC"},
|
{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-18", out: "2018-01-15 00:00:00 +0000 UTC"},
|
||||||
|
Loading…
Reference in New Issue
Block a user