diff --git a/parseany.go b/parseany.go index b5f7a28..d930ffb 100644 --- a/parseany.go +++ b/parseany.go @@ -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) } diff --git a/parseany_test.go b/parseany_test.go index 9ae5e10..6f06f8e 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -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 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))) } - -// func TestParseAMPM(t *testing.T) { -// //2014-04-26 05:24:37 PM -// ts, err := ParseAny("2014-04-26 05:24:37 PM") -// 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))) -// }