mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-07 21:43:50 +08:00
add support for milliseconds
This commit is contained in:
parent
6b774e2c87
commit
97578a0e9c
@ -301,6 +301,12 @@ iterRunes:
|
|||||||
} else {
|
} else {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
|
} else if len(datestr) >= len("1384216367189") {
|
||||||
|
if miliSecs, err := strconv.ParseInt(datestr, 10, 64); err == nil {
|
||||||
|
return time.Unix(0, miliSecs*1000*1000), nil
|
||||||
|
} else {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if secs, err := strconv.ParseInt(datestr, 10, 64); err == nil {
|
if secs, err := strconv.ParseInt(datestr, 10, 64); err == nil {
|
||||||
return time.Unix(secs, 0), nil
|
return time.Unix(secs, 0), nil
|
||||||
|
@ -223,6 +223,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-03-19 10:11:59 +0000 UTC" == fmt.Sprintf("%v", 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("1384216367189")
|
||||||
|
assert.Tf(t, err == nil, "%v", err)
|
||||||
|
//u.Debug(ts.In(time.UTC).Unix(), ts.In(time.UTC))
|
||||||
|
assert.T(t, "2013-11-12 00:32:47.189 +0000 UTC" == fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestWIP(t *testing.T) {
|
// func TestWIP(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user