mirror of
https://github.com/araddon/dateparse.git
synced 2024-12-13 01:19:53 +08:00
New zone format
This commit is contained in:
parent
064979c42e
commit
73f547e7b6
18
parseany.go
18
parseany.go
@ -56,6 +56,7 @@ const (
|
|||||||
ST_WEEKDAYCOMMADELTA
|
ST_WEEKDAYCOMMADELTA
|
||||||
ST_WEEKDAYABBREVCOMMA
|
ST_WEEKDAYABBREVCOMMA
|
||||||
ST_WEEKDAYABBREVCOMMADELTA
|
ST_WEEKDAYABBREVCOMMADELTA
|
||||||
|
ST_WEEKDAYABBREVCOMMADELTAZONE
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -296,6 +297,8 @@ iterRunes:
|
|||||||
// ST_WEEKDAYABBREVCOMMADELTA
|
// ST_WEEKDAYABBREVCOMMADELTA
|
||||||
// Mon, 02 Jan 2006 15:04:05 -0700
|
// Mon, 02 Jan 2006 15:04:05 -0700
|
||||||
// Thu, 13 Jul 2017 08:58:40 +0100
|
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||||
|
// ST_WEEKDAYABBREVCOMMADELTAZONE
|
||||||
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
switch {
|
switch {
|
||||||
case unicode.IsLetter(r):
|
case unicode.IsLetter(r):
|
||||||
continue
|
continue
|
||||||
@ -330,6 +333,8 @@ iterRunes:
|
|||||||
// ST_WEEKDAYABBREVCOMMADELTA
|
// ST_WEEKDAYABBREVCOMMADELTA
|
||||||
// Mon, 02 Jan 2006 15:04:05 -0700
|
// Mon, 02 Jan 2006 15:04:05 -0700
|
||||||
// Thu, 13 Jul 2017 08:58:40 +0100
|
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||||
|
// ST_WEEKDAYABBREVCOMMADELTAZONE
|
||||||
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
switch {
|
switch {
|
||||||
case r == '-':
|
case r == '-':
|
||||||
if i < 15 {
|
if i < 15 {
|
||||||
@ -341,6 +346,16 @@ iterRunes:
|
|||||||
state = ST_WEEKDAYABBREVCOMMADELTA
|
state = ST_WEEKDAYABBREVCOMMADELTA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ST_WEEKDAYABBREVCOMMADELTA:
|
||||||
|
// ST_WEEKDAYABBREVCOMMADELTA
|
||||||
|
// Mon, 02 Jan 2006 15:04:05 -0700
|
||||||
|
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||||
|
// ST_WEEKDAYABBREVCOMMADELTAZONE
|
||||||
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
|
if r == '(' {
|
||||||
|
state = ST_WEEKDAYABBREVCOMMADELTAZONE
|
||||||
|
}
|
||||||
|
|
||||||
case ST_ALPHAWS: // Starts alpha then whitespace
|
case ST_ALPHAWS: // Starts alpha then whitespace
|
||||||
// Mon Jan _2 15:04:05 2006
|
// Mon Jan _2 15:04:05 2006
|
||||||
// Mon Jan _2 15:04:05 MST 2006
|
// Mon Jan _2 15:04:05 MST 2006
|
||||||
@ -680,6 +695,9 @@ iterRunes:
|
|||||||
// Thu, 13 Jul 2017 08:58:40 +0100
|
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||||
// RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
|
// RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
|
||||||
return time.Parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr)
|
return time.Parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr)
|
||||||
|
case ST_WEEKDAYABBREVCOMMADELTAZONE:
|
||||||
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
|
return time.Parse("Mon, 02 Jan 2006 15:04:05 -0700 (CEST)", datestr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return time.Time{}, fmt.Errorf("Could not find date format for %s", datestr)
|
return time.Time{}, fmt.Errorf("Could not find date format for %s", datestr)
|
||||||
|
@ -153,6 +153,9 @@ func TestParse(t *testing.T) {
|
|||||||
ts = MustParse("Mon, 02-Jan-06 15:04:05 MST")
|
ts = MustParse("Mon, 02-Jan-06 15:04:05 MST")
|
||||||
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2006-01-02 15:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts = MustParse("Tue, 11 Jul 2017 16:28:13 +0200 (CEST)")
|
||||||
|
assert.Equal(t, "2017-07-11 14:28:13 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
ts = MustParse("Thu, 13 Jul 2017 08:58:40 +0100")
|
ts = MustParse("Thu, 13 Jul 2017 08:58:40 +0100")
|
||||||
assert.Equal(t, "2017-07-13 07:58:40 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2017-07-13 07:58:40 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user