mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 11:16:12 +08:00
Skip white space
This commit is contained in:
parent
19ef6a25eb
commit
8b765a5302
@ -1097,10 +1097,12 @@ iterRunes:
|
||||
// Thu, 4 Jan 2018 17:53:36 +0000
|
||||
// Tue, 11 Jul 2017 16:28:13 +0200 (CEST)
|
||||
// Mon, 02-Jan-06 15:04:05 MST
|
||||
var offset int
|
||||
switch r {
|
||||
case ' ':
|
||||
for i+1 < len(datestr) && datestr[i+1] == ' ' {
|
||||
i++
|
||||
offset++
|
||||
}
|
||||
fallthrough
|
||||
case '-':
|
||||
@ -1111,11 +1113,11 @@ iterRunes:
|
||||
p.setDay()
|
||||
p.moi = i + 1
|
||||
} else if p.yeari == 0 {
|
||||
p.molen = i - p.moi
|
||||
p.molen = i - p.moi - offset
|
||||
p.set(p.moi, "Jan")
|
||||
p.yeari = i + 1
|
||||
} else {
|
||||
p.yearlen = i - p.yeari
|
||||
p.yearlen = i - p.yeari - offset
|
||||
p.setYear()
|
||||
p.stateTime = timeStart
|
||||
break iterRunes
|
||||
|
@ -427,17 +427,20 @@ func TestParse(t *testing.T) {
|
||||
time.Local = time.UTC
|
||||
|
||||
zeroTime := time.Time{}.Unix()
|
||||
ts, err := ParseAny("INVALID")
|
||||
assert.Equal(t, zeroTime, ts.Unix())
|
||||
assert.NotEqual(t, nil, err)
|
||||
t.Run("Invalid", func(t *testing.T) {
|
||||
ts, err := ParseAny("INVALID")
|
||||
assert.Equal(t, zeroTime, ts.Unix())
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
assert.Equal(t, true, testDidPanic("NOT GONNA HAPPEN"))
|
||||
// https://github.com/golang/go/issues/5294
|
||||
_, err = ParseAny(time.RFC3339)
|
||||
assert.NotEqual(t, nil, err)
|
||||
assert.Equal(t, true, testDidPanic("NOT GONNA HAPPEN"))
|
||||
// https://github.com/golang/go/issues/5294
|
||||
_, err = ParseAny(time.RFC3339)
|
||||
assert.NotEqual(t, nil, err)
|
||||
})
|
||||
|
||||
for _, th := range testInputs {
|
||||
t.Run(th.in, func(t *testing.T) {
|
||||
var ts time.Time
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("error: %s", r)
|
||||
@ -470,16 +473,24 @@ func TestParse(t *testing.T) {
|
||||
|
||||
// some errors
|
||||
|
||||
assert.Equal(t, true, testDidPanic(`{"ts":"now"}`))
|
||||
t.Run("", func(t *testing.T) {
|
||||
assert.Equal(t, true, testDidPanic(`{"ts":"now"}`))
|
||||
})
|
||||
|
||||
_, err = ParseAny("138421636711122233311111") // too many digits
|
||||
assert.NotEqual(t, nil, err)
|
||||
t.Run("too many digits", func(t *testing.T) {
|
||||
_, err := ParseAny("138421636711122233311111") // too many digits
|
||||
assert.NotEqual(t, nil, err)
|
||||
})
|
||||
|
||||
_, err = ParseAny("-1314")
|
||||
assert.NotEqual(t, nil, err)
|
||||
t.Run("negative number", func(t *testing.T) {
|
||||
_, err := ParseAny("-1314")
|
||||
assert.NotEqual(t, nil, err)
|
||||
})
|
||||
|
||||
_, err = ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist so error
|
||||
assert.NotEqual(t, nil, err)
|
||||
t.Run("month doesn't exist", func(t *testing.T) {
|
||||
_, err := ParseAny("2014-13-13 08:20:13,787") // month 13 doesn't exist so error
|
||||
assert.NotEqual(t, nil, err)
|
||||
})
|
||||
}
|
||||
|
||||
func testDidPanic(datestr string) (paniced bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user