diff --git a/parseany.go b/parseany.go index d6540d4..9e98764 100644 --- a/parseany.go +++ b/parseany.go @@ -61,7 +61,7 @@ const ( dateAlphaWsDigitMoreWs dateAlphaWsDigitMoreWsYear dateAlphaWsMonth - dateAlphaWsMonthMore + dateAlphaWsMonthMore // 25 dateAlphaWsMonthSuffix dateAlphaWsMore dateAlphaWsAtTime @@ -530,6 +530,7 @@ iterRunes: // Mon Jan 02 15:04:05 -0700 2006 // Mon Aug 10 15:44:11 UTC+0100 2015 // Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) + // Jan 20 21:17:01 // dateAlphaWSDigit // May 8, 2009 5:57:51 PM // oct 1, 1970 @@ -624,6 +625,7 @@ iterRunes: // May 8 2009 5:57:51 PM // oct 1, 1970 // oct 7, '70 + // Jan 20 21:17:01 switch { case unicode.IsLetter(r): p.set(0, "Mon") @@ -641,6 +643,7 @@ iterRunes: // oct 1, 1970 // oct 7, '70 // oct. 7, 1970 + // Jan 20 21:17:01 if r == ',' { p.daylen = i - p.dayi p.setDay() @@ -671,9 +674,21 @@ iterRunes: // May 05, 2005, 05:05:05 // oct 1, 1970 // oct 7, '70 + // Jan 20 21:17:01 switch r { case '\'': p.yeari = i + 1 + case ':': + // x + // Jan 20 21:17:01 + p.stateTime = timeStart + p.dayi = i - 2 + p.setDay() + i = i - 3 + // this is a crap format, no year is in it which + // go will not parse. So, we have to do some ugly crap to create format. + datestr = fmt.Sprintf("%s %d %s", datestr[:i], time.Now().Year(), datestr[i:]) + return parseTime(datestr, loc) case ' ', ',': // x // May 8, 2009 5:57:51 PM @@ -685,7 +700,6 @@ iterRunes: p.stateTime = timeStart break iterRunes } - case dateAlphaWsAlpha: // Mon Jan _2 15:04:05 2006 // Mon Jan 02 15:04:05 -0700 2006 diff --git a/parseany_test.go b/parseany_test.go index e141bd6..b3f41ee 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -11,8 +11,8 @@ import ( func TestOne(t *testing.T) { time.Local = time.UTC var ts time.Time - ts = MustParse("September 17, 2012, 10:10:09") - assert.Equal(t, "2012-09-17 10:10:09 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) + ts = MustParse("Jan 20 21:17:01") + assert.Equal(t, "2019-01-20 21:17:01 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) } type dateTest struct { @@ -88,6 +88,8 @@ var testInputs = []dateTest{ {in: "May 7, 2012", out: "2012-05-07 00:00:00 +0000 UTC"}, {in: "June 7, 2012", out: "2012-06-07 00:00:00 +0000 UTC"}, {in: "June 7 2012", out: "2012-06-07 00:00:00 +0000 UTC"}, + // Mon dd hh:mm.ss + {in: "Sep 17 15:01:00", out: fmt.Sprintf("%d-09-17 15:01:00 +0000 UTC", time.Now().Year())}, // Month dd[th,nd,st,rd] yyyy {in: "September 17th, 2012", out: "2012-09-17 00:00:00 +0000 UTC"}, {in: "September 17th 2012", out: "2012-09-17 00:00:00 +0000 UTC"},