mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
new date format
This commit is contained in:
parent
9486d2dfd3
commit
aa93a85b69
11
parseany.go
11
parseany.go
@ -51,6 +51,7 @@ iterRunes:
|
||||
case 64: // starts digit then dash 02- 1 << 2 << 5
|
||||
// 2006-01-02T15:04:05Z07:00
|
||||
// 2006-01-02T15:04:05.999999999Z07:00
|
||||
// 2012-08-03 18:31:59.257000000
|
||||
// 2014-04-26 17:24:37.3186369
|
||||
// 2016-03-14 00:00:00.000
|
||||
// 2014-05-11 08:20:13,787
|
||||
@ -64,6 +65,7 @@ iterRunes:
|
||||
}
|
||||
case 65: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 1
|
||||
// 2014-04-26 17:24:37.3186369
|
||||
// 2012-08-03 18:31:59.257000000
|
||||
// 2016-03-14 00:00:00.000
|
||||
// 2014-05-11 08:20:13,787
|
||||
// 2014-04-26 05:24:37 PM
|
||||
@ -207,8 +209,15 @@ iterRunes:
|
||||
}
|
||||
case 65: // starts digit then dash 02- then whitespace 1 << 2 << 5 + 3
|
||||
// 2014-04-26 17:24:37.3186369
|
||||
// 2012-08-03 18:31:59.257000000
|
||||
// 2016-03-14 00:00:00.000
|
||||
if len(datestr) == len("2014-04-26 05:24:37.3186369") {
|
||||
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 {
|
||||
return t, nil
|
||||
} else {
|
||||
u.Error(err)
|
||||
}
|
||||
} else if len(datestr) == len("2014-04-26 05:24:37.3186369") {
|
||||
if t, err := time.Parse("2006-01-02 15:04:05.0000000", datestr); err == nil {
|
||||
return t, nil
|
||||
} else {
|
||||
|
@ -60,79 +60,84 @@ func TestParse(t *testing.T) {
|
||||
assert.T(t, "2009-05-08 17:57:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("03/19/2012 10:11:59")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//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)))
|
||||
|
||||
ts, err = ParseAny("3/31/2014")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-03-31 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("03/31/2014")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-03-31 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("4/8/2014 22:05")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-08 22:05:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("04/08/2014 22:05")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-08 22:05:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("04/2/2014 03:00:51")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-02 03:00:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("4/02/2014 03:00:51")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-02 03:00:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("1332151919")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//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)))
|
||||
|
||||
ts, err = ParseAny("2009-08-12T22:15:09-07:00")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2009-08-13 05:15:09 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-04-26 17:24:37.3186369")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-26 17:24:37.3186369 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2012-08-03 18:31:59.257000000")
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2012-08-03 18:31:59.257 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-04-26 17:24:37.123")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-26 17:24:37.123 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-04-26 05:24:37 PM")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-26 17:24:37 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-04-26")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-04-26 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
|
||||
ts, err = ParseAny("2014-05-11 08:20:13,787")
|
||||
assert.T(t, err == nil)
|
||||
assert.Tf(t, err == nil, "%v", err)
|
||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
assert.T(t, "2014-05-11 08:20:13.787 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
}
|
||||
|
||||
func TestWIP(t *testing.T) {
|
||||
// ts, err := ParseAny("04/2/2014 03:00:51")
|
||||
// assert.T(t, err == nil)
|
||||
// ts, err := ParseAny("2012-08-03 18:31:59.257000000")
|
||||
// assert.Tf(t, err == nil, "%v", err)
|
||||
// u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||
// assert.T(t, "2014-04-02 03:00:51 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
// assert.T(t, "2012-08-03 18:31:59.257 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user