mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
Merge pull request #13 from araddon/parse_plus_offset
Parse plus offset date
This commit is contained in:
commit
c1b49336a8
21
parseany.go
21
parseany.go
@ -35,7 +35,7 @@ const (
|
||||
ST_DIGITDASHT
|
||||
ST_DIGITDASHTZ
|
||||
ST_DIGITDASHTZDIGIT
|
||||
ST_DIGITDASHTDASH
|
||||
ST_DIGITDASHTDELTA
|
||||
ST_DIGITCOMMA
|
||||
ST_DIGITCOLON
|
||||
ST_DIGITSLASH
|
||||
@ -217,9 +217,10 @@ iterRunes:
|
||||
// With another dash aka time-zone at end
|
||||
// ST_DIGITDASHTDASH
|
||||
// 2017-06-25T17:46:57.45706582-07:00
|
||||
// 2017-06-25T17:46:57+04:00
|
||||
switch {
|
||||
case r == '-':
|
||||
state = ST_DIGITDASHTDASH
|
||||
case r == '-', r == '+':
|
||||
state = ST_DIGITDASHTDELTA
|
||||
case r == 'Z':
|
||||
state = ST_DIGITDASHTZ
|
||||
}
|
||||
@ -499,16 +500,16 @@ iterRunes:
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
case ST_DIGITDASHTDASH:
|
||||
// With another dash aka time-zone at end
|
||||
case ST_DIGITDASHTDELTA:
|
||||
// With another +/- time-zone at end
|
||||
// 2006-01-02T15:04:05.999999999+07:00
|
||||
// 2006-01-02T15:04:05.999999999-07:00
|
||||
// 2006-01-02T15:04:05.99999999-07:00
|
||||
// 2006-01-02T15:04:05.9999999-07:00
|
||||
// 2006-01-02T15:04:05.999999+07:00
|
||||
// 2006-01-02T15:04:05.999999-07:00
|
||||
// 2006-01-02T15:04:05.99999-07:00
|
||||
// 2006-01-02T15:04:05.9999-07:00
|
||||
// 2006-01-02T15:04:05.999+07:00
|
||||
// 2006-01-02T15:04:05.999-07:00
|
||||
// 2006-01-02T15:04:05.99-07:00
|
||||
// 2006-01-02T15:04:05+07:00
|
||||
// 2006-01-02T15:04:05-07:00
|
||||
if t, err := time.Parse("2006-01-02T15:04:05-07:00", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
|
@ -393,6 +393,14 @@ func TestParse(t *testing.T) {
|
||||
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("2016-06-21T19:55:00+01:00")
|
||||
assertf(t, err == nil, "%v", err)
|
||||
assert(t, "2016-06-21 18:55:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2016-06-21T19:55:00.799+01:00")
|
||||
assertf(t, err == nil, "%v", err)
|
||||
assert(t, "2016-06-21 18:55:00.799 +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)))
|
||||
|
Loading…
Reference in New Issue
Block a user