Skip to content

Commit 00e168d

Browse files
committed
fix date "1 July 2013" closes #70
1 parent f056aa2 commit 00e168d

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

example/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var examples = []string{
3232
"7 oct 70",
3333
"7 oct 1970",
3434
"03 February 2013",
35+
"1 July 2013",
3536
"2013-Feb-03",
3637
// mm/dd/yy
3738
"3/31/2014",

parseany.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,19 @@ iterRunes:
462462
p.daylen = p.part1Len
463463
p.setDay()
464464
p.stateTime = timeStart
465-
if i <= len("12 Feb") {
465+
if i > p.daylen+len(" Sep") { // November etc
466+
// If len greather than space + 3 it must be full month
467+
p.stateDate = dateDigitWsMolong
468+
} else {
469+
// If len=3, the might be Feb or May? Ie ambigous abbreviated but
470+
// we can parse may with either. BUT, that means the
471+
// format may not be correct?
472+
// mo := strings.ToLower(datestr[p.daylen+1 : i])
473+
// gou.Warnf("mo = %q", mo)
466474
p.moi = p.daylen + 1
467-
p.molen = 3
475+
p.molen = i - p.moi
468476
p.set(p.moi, "Jan")
469477
p.stateDate = dateDigitWsMoYear
470-
} else {
471-
p.stateDate = dateDigitWsMolong
472478
}
473479
}
474480

parseany_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import (
1111
func TestOne(t *testing.T) {
1212
time.Local = time.UTC
1313
var ts time.Time
14-
ts = MustParse("11-Jun-11 18:09:59")
15-
// "2016-06-29 18:09:59 +0000 UTC"
16-
assert.Equal(t, "2011-06-11 18:09:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
14+
ts = MustParse("1 May 2013")
15+
assert.Equal(t, "2013-05-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
1716
}
1817

1918
type dateTest struct {
@@ -36,6 +35,10 @@ var testInputs = []dateTest{
3635
{in: "May 8, 2009 5:7:51 PM", out: "2009-05-08 17:07:51 +0000 UTC"},
3736
{in: "7 oct 70", out: "1970-10-07 00:00:00 +0000 UTC"},
3837
{in: "7 oct 1970", out: "1970-10-07 00:00:00 +0000 UTC"},
38+
{in: "7 May 1970", out: "1970-05-07 00:00:00 +0000 UTC"},
39+
{in: "7 Sep 1970", out: "1970-09-07 00:00:00 +0000 UTC"},
40+
{in: "7 June 1970", out: "1970-06-07 00:00:00 +0000 UTC"},
41+
{in: "7 September 1970", out: "1970-09-07 00:00:00 +0000 UTC"},
3942
// ANSIC = "Mon Jan _2 15:04:05 2006"
4043
{in: "Mon Jan 2 15:04:05 2006", out: "2006-01-02 15:04:05 +0000 UTC"},
4144
{in: "Thu May 8 17:57:51 2009", out: "2009-05-08 17:57:51 +0000 UTC"},

0 commit comments

Comments
 (0)