new date format for comma microseconds

This commit is contained in:
Aaron Raddon 2014-05-11 08:42:56 -07:00
parent 6e81432574
commit f85104b4d6
2 changed files with 19 additions and 22 deletions

View File

@ -78,8 +78,13 @@ iterRunes:
}
case ',':
if len(datestr) == len("2014-05-11 08:20:13,787") {
if t, err := time.Parse("2006-01-02 03:04:05,999", datestr); err == nil {
return t, nil
// go doesn't seem to parse this one natively? or did i miss it?
if t, err := time.Parse("2006-01-02 03:04:05", datestr[:i]); err == nil {
ms, err := strconv.Atoi(datestr[i+1:])
if err == nil {
return time.Unix(0, t.UnixNano()+int64(ms)*1e6), nil
}
u.Error(err)
} else {
u.Error(err)
}

View File

@ -44,7 +44,7 @@ var _ = time.April
2016-03-14 00:00:00.000
2006-01-02
2014-05-11 08:20:13,787
2014-05-11 08:20:13,787 // i couldn't find parser for this in go?
*/
@ -97,42 +97,34 @@ func TestParse(t *testing.T) {
//2014-04-26 05:24:37.3186369
ts, err = ParseAny("2014-04-26 17:24:37.3186369")
assert.T(t, err == nil)
//u.Debug(ts.Unix(), ts)
//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)))
//2014-04-26 17:24:37.123
ts, err = ParseAny("2014-04-26 17:24:37.123")
assert.T(t, err == nil)
//u.Debugf("unix=%v ts='%v'", ts.Unix(), ts)
//u.Debugf("unix=%v ts='%v'", 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)
//u.Debug(ts.Unix(), ts)
//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)
//u.Debug(ts.Unix(), ts)
//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)
//u.Debug(ts.Unix(), ts)
assert.T(t, "2014-04-26 00:00:00 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
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 TestME(t *testing.T) {
ts, err := ParseAny("2014-05-11 08:20:13,787")
assert.T(t, err == nil)
u.Debug(ts.Unix(), ts)
assert.T(t, "2014-04-26 17:24:37 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
}
// func TestParseAMPM(t *testing.T) {
// //2014-04-26 05:24:37 PM
// ts, err := ParseAny("2014-04-26 05:24:37 PM")
func TestWIP(t *testing.T) {
// ts, err := ParseAny("2014-05-11 08:20:13,787")
// assert.T(t, err == nil)
// u.Debug(ts.Unix(), ts)
// assert.T(t, "2014-04-26 17:24:37 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
// }
}