diff --git a/parseany.go b/parseany.go index 08b4450..b2f11aa 100644 --- a/parseany.go +++ b/parseany.go @@ -122,6 +122,7 @@ const ( timeWsOffsetColonAlpha timeWsOffsetColon timeWsYear // 16 + timeWsYearOffset timeOffset timeOffsetColon timeOffsetColonAlpha @@ -997,13 +998,14 @@ iterRunes: } case dateAlpha: - // dateAlphaWS + // dateAlphaWs // Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 MST 2006 // Mon Jan 02 15:04:05 -0700 2006 + // Mon Jan 02 15:04:05 2006 -0700 // Mon Aug 10 15:44:11 UTC+0100 2015 // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) - // dateAlphaWSDigit + // dateAlphaWsDigit // May 8, 2009 5:57:51 PM // oct 1, 1970 // dateAlphaWsMonth @@ -1135,6 +1137,7 @@ iterRunes: // Mon Jan _2 15:04:05 2006 // Mon Jan _2 15:04:05 MST 2006 // Mon Jan 02 15:04:05 -0700 2006 + // Mon Jan 02 15:04:05 2006 -0700 // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) // Mon Aug 10 15:44:11 UTC+0100 2015 // dateAlphaWsDigit @@ -1663,7 +1666,9 @@ iterRunes: // timeWsOffsetColonAlpha // 00:12:00 +00:00 UTC // timeWsYear - // 00:12:00 2008 + // 00:12:00 2008 + // timeWsYearOffset + // 00:12:00 2008 -0700 // timeZ // 15:04:05.99Z switch r { @@ -1688,6 +1693,23 @@ iterRunes: p.yeari = i } } + case timeWsYear: + // timeWsYearOffset + // 00:12:00 2008 -0700 + switch r { + case ' ': + p.yearlen = i - p.yeari + if !p.setYear() { + return p, unknownErr(datestr) + } + case '+', '-': + p.offseti = i + p.stateTime = timeWsYearOffset + default: + if !unicode.IsDigit(r) { + return p, unknownErr(datestr) + } + } case timeWsAlpha: // 06:20:00 UTC // 06:20:00 UTC-05 @@ -2049,7 +2071,7 @@ iterRunes: if p.mslen >= 10 { return p, fmt.Errorf("fractional seconds in %q too long near %q", datestr, string(p.datestr[p.msi:p.mslen])) } - case timeOffset, timeWsOffset: + case timeOffset, timeWsOffset, timeWsYearOffset: switch len(p.datestr) - p.offseti { case 3: // 19:55:00+01 (or 19:55:00 +01) diff --git a/parseany_test.go b/parseany_test.go index c786cf4..57a3998 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -443,6 +443,9 @@ var testInputs = []dateTest{ {in: "4/2/2014, 04:08:09", out: "2014-04-02 04:08:09 +0000 UTC"}, {in: "04/02/2014, 04:08 AM", out: "2014-04-02 04:08:00 +0000 UTC"}, {in: "04/02/2014, 04:08 PM", out: "2014-04-02 16:08:00 +0000 UTC"}, + // Git log default date format - https://github.com/araddon/dateparse/pull/92 + {in: "Thu Apr 7 15:13:13 2005 -0700", out: "2005-04-07 22:13:13 +0000 UTC"}, + {in: "Tue Dec 12 23:07:11 2023 -0700", out: "2023-12-13 06:07:11 +0000 UTC"}, // yyyy-mm-dd hh:mm:ss,000 {in: "2014-05-11 08:20:13,787", out: "2014-05-11 08:20:13.787 +0000 UTC"}, // yyyy-mm-dd hh:mm:ss +0000 @@ -1090,5 +1093,5 @@ func TestRetryAmbiguousDateWithSwap(t *testing.T) { // Convenience function for debugging a particular broken test case func TestDebug(t *testing.T) { - MustParse("Jul 9, 2012 at 5:02am (EST)") + MustParse("Tue Dec 12 23:07:11 2023 -0700") }