mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
commit
b5a89160d8
18
parseany.go
18
parseany.go
@ -56,6 +56,7 @@ const (
|
||||
ST_WEEKDAYCOMMADELTA
|
||||
ST_WEEKDAYABBREVCOMMA
|
||||
ST_WEEKDAYABBREVCOMMADELTA
|
||||
ST_WEEKDAYABBREVCOMMADELTAZONE
|
||||
)
|
||||
|
||||
var (
|
||||
@ -296,6 +297,8 @@ iterRunes:
|
||||
// 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)
|
||||
switch {
|
||||
case unicode.IsLetter(r):
|
||||
continue
|
||||
@ -330,6 +333,8 @@ iterRunes:
|
||||
// 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)
|
||||
switch {
|
||||
case r == '-':
|
||||
if i < 15 {
|
||||
@ -341,6 +346,16 @@ iterRunes:
|
||||
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
|
||||
// Mon Jan _2 15:04:05 2006
|
||||
// Mon Jan _2 15:04:05 MST 2006
|
||||
@ -680,6 +695,9 @@ iterRunes:
|
||||
// Thu, 13 Jul 2017 08:58:40 +0100
|
||||
// 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)
|
||||
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)
|
||||
|
@ -153,6 +153,9 @@ func TestParse(t *testing.T) {
|
||||
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)))
|
||||
|
||||
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")
|
||||
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