mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
parse 2006-01-02 15:04:05 -07:00
This commit is contained in:
parent
b008e51bc1
commit
62adefbf6b
15
parseany.go
15
parseany.go
@ -500,11 +500,18 @@ iterRunes:
|
||||
}
|
||||
case ST_DIGITDASHWS: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
|
||||
// 2013-04-01 22:43:22
|
||||
if t, err := time.Parse("2006-01-02 15:04:05", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
var t time.Time
|
||||
var err error
|
||||
|
||||
switch len(datestr) {
|
||||
case len("2006-01-02 15:04:05"):
|
||||
t, err = time.Parse("2006-01-02 15:04:05", datestr)
|
||||
case len("2006-01-02 15:04:05 -0700"):
|
||||
t, err = time.Parse("2006-01-02 15:04:05 -0700", datestr)
|
||||
case len("2006-01-02 15:04:05 -07:00"):
|
||||
t, err = time.Parse("2006-01-02 15:04:05 -07:00", datestr)
|
||||
}
|
||||
return t, err
|
||||
case ST_DIGITDASHWSALPHA: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
|
||||
// 2014-12-16 06:20:00 UTC
|
||||
// 2015-02-18 00:12:00 +0000 UTC
|
||||
|
@ -383,6 +383,14 @@ func TestParse(t *testing.T) {
|
||||
assertf(t, err == nil, "%v", err)
|
||||
assert(t, "2014-05-11 08:20:13.787 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-05-11 08:20:13 +00:00")
|
||||
assertf(t, err == nil, "%v", err)
|
||||
assert(t, "2014-05-11 08:20:13 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-05-11 08:20:13 +0000")
|
||||
assertf(t, err == nil, "%v", err)
|
||||
assert(t, "2014-05-11 08:20:13 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
// yyyymmdd and similar
|
||||
ts, err = ParseAny("2014")
|
||||
assertf(t, err == nil, "%v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user