Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions parseany.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (
dateAlphaWsDigitMoreWs
dateAlphaWsDigitMoreWsYear
dateAlphaWsMonth
dateAlphaWsMonthMore
dateAlphaWsMonthMore // 25
dateAlphaWsMonthSuffix
dateAlphaWsMore
dateAlphaWsAtTime
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions parseany_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"},
Expand Down