mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 03:06:11 +08:00
merge plus/minus state
This commit is contained in:
parent
47cec0dc4d
commit
91bb6b61cd
32
parseany.go
32
parseany.go
@ -35,8 +35,7 @@ const (
|
|||||||
ST_DIGITDASHT
|
ST_DIGITDASHT
|
||||||
ST_DIGITDASHTZ
|
ST_DIGITDASHTZ
|
||||||
ST_DIGITDASHTZDIGIT
|
ST_DIGITDASHTZDIGIT
|
||||||
ST_DIGITDASHTDASH
|
ST_DIGITDASHTDELTA
|
||||||
ST_DIGITDASHTPLUS
|
|
||||||
ST_DIGITCOMMA
|
ST_DIGITCOMMA
|
||||||
ST_DIGITCOLON
|
ST_DIGITCOLON
|
||||||
ST_DIGITSLASH
|
ST_DIGITSLASH
|
||||||
@ -220,10 +219,8 @@ iterRunes:
|
|||||||
// 2017-06-25T17:46:57.45706582-07:00
|
// 2017-06-25T17:46:57.45706582-07:00
|
||||||
// 2017-06-25T17:46:57+04:00
|
// 2017-06-25T17:46:57+04:00
|
||||||
switch {
|
switch {
|
||||||
case r == '-':
|
case r == '-', r == '+':
|
||||||
state = ST_DIGITDASHTDASH
|
state = ST_DIGITDASHTDELTA
|
||||||
case r == '+':
|
|
||||||
state = ST_DIGITDASHTPLUS
|
|
||||||
case r == 'Z':
|
case r == 'Z':
|
||||||
state = ST_DIGITDASHTZ
|
state = ST_DIGITDASHTZ
|
||||||
}
|
}
|
||||||
@ -503,27 +500,16 @@ iterRunes:
|
|||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ST_DIGITDASHTDASH:
|
case ST_DIGITDASHTDELTA:
|
||||||
// With another dash aka time-zone at end
|
// With another +/- time-zone at end
|
||||||
// 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.99999-07:00
|
|
||||||
// 2006-01-02T15:04:05.9999-07:00
|
|
||||||
// 2006-01-02T15:04:05.999-07:00
|
|
||||||
// 2006-01-02T15:04:05.99-07:00
|
|
||||||
if t, err := time.Parse("2006-01-02T15:04:05-07:00", datestr); err == nil {
|
|
||||||
return t, nil
|
|
||||||
} else {
|
|
||||||
return time.Time{}, err
|
|
||||||
}
|
|
||||||
case ST_DIGITDASHTPLUS:
|
|
||||||
// With a plus aka 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.999999999-07:00
|
||||||
// 2006-01-02T15:04:05.999999+07:00
|
// 2006-01-02T15:04:05.999999+07:00
|
||||||
|
// 2006-01-02T15:04:05.999999-07:00
|
||||||
// 2006-01-02T15:04:05.999+07:00
|
// 2006-01-02T15:04:05.999+07:00
|
||||||
|
// 2006-01-02T15:04:05.999-07:00
|
||||||
// 2006-01-02T15:04:05+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 {
|
if t, err := time.Parse("2006-01-02T15:04:05-07:00", datestr); err == nil {
|
||||||
return t, nil
|
return t, nil
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user