new date format

This commit is contained in:
Aaron Raddon 2014-05-11 18:22:16 -07:00
parent aa93a85b69
commit 497d740c1b
2 changed files with 18 additions and 4 deletions

View File

@ -56,6 +56,7 @@ iterRunes:
// 2016-03-14 00:00:00.000
// 2014-05-11 08:20:13,787
// 2006-01-02
// 2013-04-01 22:43:22
// 2014-04-26 05:24:37 PM
switch {
case r == ' ':
@ -67,6 +68,7 @@ iterRunes:
// 2014-04-26 17:24:37.3186369
// 2012-08-03 18:31:59.257000000
// 2016-03-14 00:00:00.000
// 2013-04-01 22:43:22
// 2014-05-11 08:20:13,787
// 2014-04-26 05:24:37 PM
switch r {
@ -211,6 +213,7 @@ iterRunes:
// 2014-04-26 17:24:37.3186369
// 2012-08-03 18:31:59.257000000
// 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 t, err := time.Parse("2006-01-02 15:04:05.000000000", datestr); err == nil {
return t, nil
@ -229,6 +232,12 @@ iterRunes:
} else {
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/
// 3/1/2014

View File

@ -114,6 +114,11 @@ func TestParse(t *testing.T) {
//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("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")
assert.Tf(t, err == nil, "%v", err)
//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) {
// 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("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)))
}