mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-14 11:31:33 +08:00
commit
b008e51bc1
17
parseany.go
17
parseany.go
@ -209,22 +209,9 @@ iterRunes:
|
|||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// updated to include timestamps of different precisions
|
if t, err := time.Parse("2006-01-02T15:04:05Z", datestr); err == nil {
|
||||||
if t, err := time.Parse("2006-01-02T15:04:05.999999999Z", datestr); err == nil {
|
|
||||||
return t, nil
|
return t, nil
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.99999999Z", datestr); err == nil {
|
} else if t, err := time.Parse("2006-01-02T15:04:05", datestr); err == nil {
|
||||||
return t, nil
|
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.9999999Z", datestr); err == nil {
|
|
||||||
return t, nil
|
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.999999Z", datestr); err == nil {
|
|
||||||
return t, nil
|
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.99999Z", datestr); err == nil {
|
|
||||||
return t, nil
|
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.9999Z", datestr); err == nil {
|
|
||||||
return t, nil
|
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.999Z", datestr); err == nil {
|
|
||||||
return t, nil
|
|
||||||
} else if t, err := time.Parse("2006-01-02T15:04:05.99Z", datestr); err == nil {
|
|
||||||
return t, nil
|
return t, nil
|
||||||
} else {
|
} else {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
|
@ -270,6 +270,30 @@ func TestParse(t *testing.T) {
|
|||||||
assertf(t, err == nil, "%v", err)
|
assertf(t, err == nil, "%v", err)
|
||||||
assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2009-08-12T22:15:09.99Z")
|
||||||
|
assertf(t, err == nil, "%v", err)
|
||||||
|
assert(t, "2009-08-12 22:15:09.99 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2009-08-12T22:15:09.9999Z")
|
||||||
|
assertf(t, err == nil, "%v", err)
|
||||||
|
assert(t, "2009-08-12 22:15:09.9999 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2009-08-12T22:15:09.99999999Z")
|
||||||
|
assertf(t, err == nil, "%v", err)
|
||||||
|
assert(t, "2009-08-12 22:15:09.99999999 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2009-08-12T22:15:09.123")
|
||||||
|
assertf(t, err == nil, "%v", err)
|
||||||
|
assert(t, "2009-08-12 22:15:09.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2009-08-12T22:15:09.12")
|
||||||
|
assertf(t, err == nil, "%v", err)
|
||||||
|
assert(t, "2009-08-12 22:15:09.12 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2009-08-12T22:15:09.1")
|
||||||
|
assertf(t, err == nil, "%v", err)
|
||||||
|
assert(t, "2009-08-12 22:15:09.1 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
ts, err = ParseAny("2009-08-12T22:15:09")
|
ts, err = ParseAny("2009-08-12T22:15:09")
|
||||||
assertf(t, err == nil, "%v", err)
|
assertf(t, err == nil, "%v", err)
|
||||||
assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert(t, "2009-08-12 22:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
Loading…
Reference in New Issue
Block a user