fix date "1 July 2013" closes #70

This commit is contained in:
Aaron Raddon 2018-10-20 12:01:51 -07:00
parent f056aa227c
commit 00e168d348
3 changed files with 17 additions and 7 deletions

View File

@ -32,6 +32,7 @@ var examples = []string{
"7 oct 70",
"7 oct 1970",
"03 February 2013",
"1 July 2013",
"2013-Feb-03",
// mm/dd/yy
"3/31/2014",

View File

@ -462,13 +462,19 @@ iterRunes:
p.daylen = p.part1Len
p.setDay()
p.stateTime = timeStart
if i <= len("12 Feb") {
if i > p.daylen+len(" Sep") { // November etc
// If len greather than space + 3 it must be full month
p.stateDate = dateDigitWsMolong
} else {
// If len=3, the might be Feb or May? Ie ambigous abbreviated but
// we can parse may with either. BUT, that means the
// format may not be correct?
// mo := strings.ToLower(datestr[p.daylen+1 : i])
// gou.Warnf("mo = %q", mo)
p.moi = p.daylen + 1
p.molen = 3
p.molen = i - p.moi
p.set(p.moi, "Jan")
p.stateDate = dateDigitWsMoYear
} else {
p.stateDate = dateDigitWsMolong
}
}

View File

@ -11,9 +11,8 @@ import (
func TestOne(t *testing.T) {
time.Local = time.UTC
var ts time.Time
ts = MustParse("11-Jun-11 18:09:59")
// "2016-06-29 18:09:59 +0000 UTC"
assert.Equal(t, "2011-06-11 18:09:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
ts = MustParse("1 May 2013")
assert.Equal(t, "2013-05-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
}
type dateTest struct {
@ -36,6 +35,10 @@ var testInputs = []dateTest{
{in: "May 8, 2009 5:7:51 PM", out: "2009-05-08 17:07:51 +0000 UTC"},
{in: "7 oct 70", out: "1970-10-07 00:00:00 +0000 UTC"},
{in: "7 oct 1970", out: "1970-10-07 00:00:00 +0000 UTC"},
{in: "7 May 1970", out: "1970-05-07 00:00:00 +0000 UTC"},
{in: "7 Sep 1970", out: "1970-09-07 00:00:00 +0000 UTC"},
{in: "7 June 1970", out: "1970-06-07 00:00:00 +0000 UTC"},
{in: "7 September 1970", out: "1970-09-07 00:00:00 +0000 UTC"},
// ANSIC = "Mon Jan _2 15:04:05 2006"
{in: "Mon Jan 2 15:04:05 2006", out: "2006-01-02 15:04:05 +0000 UTC"},
{in: "Thu May 8 17:57:51 2009", out: "2009-05-08 17:57:51 +0000 UTC"},