mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-14 11:31:33 +08:00
Added support for timestamps like: "2006-01-02 15:04:05 UTC"
This commit is contained in:
parent
26dc426a1c
commit
d6e91490c7
12
parseany.go
12
parseany.go
@ -127,7 +127,12 @@ iterRunes:
|
|||||||
// 2006-01-02T15:04:05.999999999Z07:00
|
// 2006-01-02T15:04:05.999999999Z07:00
|
||||||
// 2006-01-02T15:04:05.999999999Z
|
// 2006-01-02T15:04:05.999999999Z
|
||||||
// 2006-01-02T15:04:05.99999999Z
|
// 2006-01-02T15:04:05.99999999Z
|
||||||
// 2013-06-16T06:57:48.9999999Z
|
// 2006-01-02T15:04:05.9999999Z
|
||||||
|
// 2006-01-02T15:04:05.999999Z
|
||||||
|
// 2006-01-02T15:04:05.99999Z
|
||||||
|
// 2006-01-02T15:04:05.9999Z
|
||||||
|
// 2006-01-02T15:04:05.999Z
|
||||||
|
// 2006-01-02T15:04:05.99Z
|
||||||
if len(datestr) == len("2006-01-02T15:04:05Z07:00") {
|
if len(datestr) == len("2006-01-02T15:04:05Z07:00") {
|
||||||
if t, err := time.Parse("2006-01-02T15:04:05Z07:00", datestr); err == nil {
|
if t, err := time.Parse("2006-01-02T15:04:05Z07:00", datestr); err == nil {
|
||||||
return t, nil
|
return t, nil
|
||||||
@ -317,6 +322,7 @@ iterRunes:
|
|||||||
// 2012-08-03 18:31:59.257000000
|
// 2012-08-03 18:31:59.257000000
|
||||||
// 2016-03-14 00:00:00.000
|
// 2016-03-14 00:00:00.000
|
||||||
// 2013-04-01 22:43:22
|
// 2013-04-01 22:43:22
|
||||||
|
// 2014-12-16 06:20:00 UTC
|
||||||
if len(datestr) == len("2012-08-03 18:31:59.257000000") {
|
if len(datestr) == len("2012-08-03 18:31:59.257000000") {
|
||||||
if t, err := time.Parse("2006-01-02 15:04:05.000000000", datestr); err == nil {
|
if t, err := time.Parse("2006-01-02 15:04:05.000000000", datestr); err == nil {
|
||||||
return t, nil
|
return t, nil
|
||||||
@ -329,9 +335,13 @@ iterRunes:
|
|||||||
} else {
|
} else {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
|
// the strings "2014-04-26 05:24:37.000" and "2014-12-16 06:20:00 UTC"
|
||||||
|
// have the same length so I'll throw them under the same else if..
|
||||||
} else if len(datestr) == len("2014-04-26 05:24:37.000") {
|
} else if len(datestr) == len("2014-04-26 05:24:37.000") {
|
||||||
if t, err := time.Parse("2006-01-02 15:04:05.000", datestr); err == nil {
|
if t, err := time.Parse("2006-01-02 15:04:05.000", datestr); err == nil {
|
||||||
return t, nil
|
return t, nil
|
||||||
|
} else if t, err := time.Parse("2006-01-02 15:04:05 UTC", datestr); err == nil {
|
||||||
|
return t, nil
|
||||||
} else {
|
} else {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
|
@ -223,6 +223,10 @@ func TestParse(t *testing.T) {
|
|||||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.T(t, "2012-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2014-12-16 06:20:00 UTC")
|
||||||
|
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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestWIP(t *testing.T) {
|
// func TestWIP(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user