mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
new date format closes #32
This commit is contained in:
parent
626fadf64d
commit
031c380915
@ -69,6 +69,7 @@ var examples = []string{
|
|||||||
"Mon, 02 Jan 2006 15:04:05 MST",
|
"Mon, 02 Jan 2006 15:04:05 MST",
|
||||||
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
|
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
|
||||||
"Mon, 02 Jan 2006 15:04:05 -0700",
|
"Mon, 02 Jan 2006 15:04:05 -0700",
|
||||||
|
"Thu, 4 Jan 2018 17:53:36 +0000",
|
||||||
"Mon Aug 10 15:44:11 UTC+0100 2015",
|
"Mon Aug 10 15:44:11 UTC+0100 2015",
|
||||||
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
|
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
|
||||||
"12 Feb 2006, 19:17",
|
"12 Feb 2006, 19:17",
|
||||||
@ -176,6 +177,7 @@ func main() {
|
|||||||
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
|
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
|
||||||
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
|
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
|
||||||
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
|
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
|
||||||
|
| Thu, 4 Jan 2018 17:53:36 +0000 | 2018-01-04 17:53:36 +0000 UTC |
|
||||||
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
|
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
|
||||||
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
|
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
|
||||||
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
|
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
|
||||||
|
@ -18,6 +18,7 @@ var examples = []string{
|
|||||||
"Mon, 02 Jan 2006 15:04:05 MST",
|
"Mon, 02 Jan 2006 15:04:05 MST",
|
||||||
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
|
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
|
||||||
"Mon, 02 Jan 2006 15:04:05 -0700",
|
"Mon, 02 Jan 2006 15:04:05 -0700",
|
||||||
|
"Thu, 4 Jan 2018 17:53:36 +0000",
|
||||||
"Mon Aug 10 15:44:11 UTC+0100 2015",
|
"Mon Aug 10 15:44:11 UTC+0100 2015",
|
||||||
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
|
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
|
||||||
"12 Feb 2006, 19:17",
|
"12 Feb 2006, 19:17",
|
||||||
@ -125,6 +126,7 @@ func main() {
|
|||||||
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
|
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
|
||||||
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
|
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
|
||||||
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
|
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
|
||||||
|
| Thu, 4 Jan 2018 17:53:36 +0000 | 2018-01-04 17:53:36 +0000 UTC |
|
||||||
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
|
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
|
||||||
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
|
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
|
||||||
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
|
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
|
||||||
|
@ -487,6 +487,7 @@ iterRunes:
|
|||||||
// stateWeekdayAbbrevCommaOffset
|
// stateWeekdayAbbrevCommaOffset
|
||||||
// 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
|
||||||
|
// Thu, 4 Jan 2018 17:53:36 +0000
|
||||||
// stateWeekdayAbbrevCommaOffsetZone
|
// stateWeekdayAbbrevCommaOffsetZone
|
||||||
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
switch {
|
switch {
|
||||||
@ -503,6 +504,7 @@ iterRunes:
|
|||||||
// stateWeekdayAbbrevCommaOffset
|
// stateWeekdayAbbrevCommaOffset
|
||||||
// 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
|
||||||
|
// Thu, 4 Jan 2018 17:53:36 +0000
|
||||||
// stateWeekdayAbbrevCommaOffsetZone
|
// stateWeekdayAbbrevCommaOffsetZone
|
||||||
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
if r == '(' {
|
if r == '(' {
|
||||||
@ -890,6 +892,12 @@ iterRunes:
|
|||||||
// 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
|
||||||
// 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
|
||||||
|
//
|
||||||
|
// Thu, 4 Jan 2018 17:53:36 +0000
|
||||||
|
if len(datestr) > 10 && datestr[6] == ' ' {
|
||||||
|
// this really appears to be an invalid RFC1123 with non zero filled day
|
||||||
|
return parse("Mon, 2 Jan 2006 15:04:05 -0700", datestr, loc)
|
||||||
|
}
|
||||||
return parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr, loc)
|
return parse("Mon, 02 Jan 2006 15:04:05 -0700", datestr, loc)
|
||||||
case stateWeekdayAbbrevCommaOffsetZone:
|
case stateWeekdayAbbrevCommaOffsetZone:
|
||||||
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||||
|
@ -170,6 +170,9 @@ func TestParse(t *testing.T) {
|
|||||||
ts = MustParse("Mon, 02 Jan 2006 15:04:05 -0700")
|
ts = MustParse("Mon, 02 Jan 2006 15:04:05 -0700")
|
||||||
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2006-01-02 22:04:05 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts = MustParse("Thu, 4 Jan 2018 17:53:36 +0000")
|
||||||
|
assert.Equal(t, "2018-01-04 17:53:36 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
// not sure if this is anything close to a standard, never seen it before
|
// not sure if this is anything close to a standard, never seen it before
|
||||||
ts = MustParse("12 Feb 2006, 19:17")
|
ts = MustParse("12 Feb 2006, 19:17")
|
||||||
assert.Equal(t, "2006-02-12 19:17:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.Equal(t, "2006-02-12 19:17:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
Loading…
Reference in New Issue
Block a user