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
aa93a85b69
commit
497d740c1b
@ -56,6 +56,7 @@ iterRunes:
|
|||||||
// 2016-03-14 00:00:00.000
|
// 2016-03-14 00:00:00.000
|
||||||
// 2014-05-11 08:20:13,787
|
// 2014-05-11 08:20:13,787
|
||||||
// 2006-01-02
|
// 2006-01-02
|
||||||
|
// 2013-04-01 22:43:22
|
||||||
// 2014-04-26 05:24:37 PM
|
// 2014-04-26 05:24:37 PM
|
||||||
switch {
|
switch {
|
||||||
case r == ' ':
|
case r == ' ':
|
||||||
@ -67,6 +68,7 @@ iterRunes:
|
|||||||
// 2014-04-26 17:24:37.3186369
|
// 2014-04-26 17:24:37.3186369
|
||||||
// 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
|
||||||
// 2014-05-11 08:20:13,787
|
// 2014-05-11 08:20:13,787
|
||||||
// 2014-04-26 05:24:37 PM
|
// 2014-04-26 05:24:37 PM
|
||||||
switch r {
|
switch r {
|
||||||
@ -211,6 +213,7 @@ iterRunes:
|
|||||||
// 2014-04-26 17:24:37.3186369
|
// 2014-04-26 17:24:37.3186369
|
||||||
// 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
|
||||||
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
|
||||||
@ -229,6 +232,12 @@ iterRunes:
|
|||||||
} else {
|
} else {
|
||||||
u.Error(err)
|
u.Error(err)
|
||||||
}
|
}
|
||||||
|
} else if len(datestr) == len("2013-04-01 22:43:22") {
|
||||||
|
if t, err := time.Parse("2006-01-02 15:04:05", datestr); err == nil {
|
||||||
|
return t, nil
|
||||||
|
} else {
|
||||||
|
u.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 256: // starts digit then slash 02/
|
case 256: // starts digit then slash 02/
|
||||||
// 3/1/2014
|
// 3/1/2014
|
||||||
|
@ -114,6 +114,11 @@ 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-08-03 18:31:59.257 +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)))
|
||||||
|
|
||||||
|
ts, err = ParseAny("2013-04-01 22:43:22")
|
||||||
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
|
assert.T(t, "2013-04-01 22:43:22 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
ts, err = ParseAny("2014-04-26 17:24:37.123")
|
ts, err = ParseAny("2014-04-26 17:24:37.123")
|
||||||
assert.Tf(t, err == nil, "%v", err)
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
@ -136,8 +141,8 @@ func TestParse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWIP(t *testing.T) {
|
func TestWIP(t *testing.T) {
|
||||||
// ts, err := ParseAny("2012-08-03 18:31:59.257000000")
|
ts, err := ParseAny("2013-04-01 22:43:22")
|
||||||
// assert.Tf(t, err == nil, "%v", err)
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
// 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-08-03 18:31:59.257 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
assert.T(t, "2013-04-01 22:43:22 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user