mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
add support for GMT formatted offsets
This commit is contained in:
parent
86f3852b68
commit
c1159e2c50
24
parseany.go
24
parseany.go
@ -497,25 +497,41 @@ iterRunes:
|
||||
if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
if t, err := time.Parse("2006-01-02 15:04:05 GMT", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
case len("2015-02-18 00:12:00 +0000 UTC"):
|
||||
if t, err := time.Parse("2006-01-02 15:04:05 +0000 UTC", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
if t, err = time.Parse("2006-01-02 15:04:05 +0000 GMT", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
case len("2015-09-30 18:48:56.35272715 +0000 UTC"):
|
||||
if t, err := time.Parse("2006-01-02 15:04:05.00000000 +0000 UTC", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
if t, err := time.Parse("2006-01-02 15:04:05.00000000 +0000 GMT", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
case len("2015-06-25 01:25:37.115208593 +0000 UTC"):
|
||||
if t, err := time.Parse("2006-01-02 15:04:05.000000000 +0000 UTC", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
if t, err := time.Parse("2006-01-02 15:04:05.000000000 +0000 GMT", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
case ST_DIGITSLASH: // starts digit then slash 02/ (but nothing else)
|
||||
|
@ -117,6 +117,10 @@ func TestParse(t *testing.T) {
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2006-01-02 22:04:05 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2015-02-18 00:12:00 +0000 GMT")
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
assert.T(t, "2015-02-18 00:12:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
// Golang Native Format
|
||||
ts, err = ParseAny("2015-02-18 00:12:00 +0000 UTC")
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
@ -277,6 +281,11 @@ func TestParse(t *testing.T) {
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-12-16 06:20:00 GMT")
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-12-16 06:20:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-04-26 05:24:37 PM")
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
|
Loading…
Reference in New Issue
Block a user