mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
fix date "1 July 2013" closes #70
This commit is contained in:
parent
f056aa227c
commit
00e168d348
@ -32,6 +32,7 @@ var examples = []string{
|
|||||||
"7 oct 70",
|
"7 oct 70",
|
||||||
"7 oct 1970",
|
"7 oct 1970",
|
||||||
"03 February 2013",
|
"03 February 2013",
|
||||||
|
"1 July 2013",
|
||||||
"2013-Feb-03",
|
"2013-Feb-03",
|
||||||
// mm/dd/yy
|
// mm/dd/yy
|
||||||
"3/31/2014",
|
"3/31/2014",
|
||||||
|
14
parseany.go
14
parseany.go
@ -462,13 +462,19 @@ iterRunes:
|
|||||||
p.daylen = p.part1Len
|
p.daylen = p.part1Len
|
||||||
p.setDay()
|
p.setDay()
|
||||||
p.stateTime = timeStart
|
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.moi = p.daylen + 1
|
||||||
p.molen = 3
|
p.molen = i - p.moi
|
||||||
p.set(p.moi, "Jan")
|
p.set(p.moi, "Jan")
|
||||||
p.stateDate = dateDigitWsMoYear
|
p.stateDate = dateDigitWsMoYear
|
||||||
} else {
|
|
||||||
p.stateDate = dateDigitWsMolong
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,8 @@ import (
|
|||||||
func TestOne(t *testing.T) {
|
func TestOne(t *testing.T) {
|
||||||
time.Local = time.UTC
|
time.Local = time.UTC
|
||||||
var ts time.Time
|
var ts time.Time
|
||||||
ts = MustParse("11-Jun-11 18:09:59")
|
ts = MustParse("1 May 2013")
|
||||||
// "2016-06-29 18:09:59 +0000 UTC"
|
assert.Equal(t, "2013-05-01 00:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
assert.Equal(t, "2011-06-11 18:09:59 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type dateTest struct {
|
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: "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 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 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"
|
// 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: "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"},
|
{in: "Thu May 8 17:57:51 2009", out: "2009-05-08 17:57:51 +0000 UTC"},
|
||||||
|
Loading…
Reference in New Issue
Block a user