mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-18 18:56:47 +08:00
easier parsing of comma milliseconds
This commit is contained in:
parent
163a0a8ac8
commit
62e766bf9e
18
parseany.go
18
parseany.go
@ -777,17 +777,12 @@ iterRunes:
|
||||
}
|
||||
switch r {
|
||||
case ',':
|
||||
if len(datestr) == len("2014-05-11 08:20:13,787") {
|
||||
// go doesn't seem to parse this one natively? or did i miss it?
|
||||
t, err := parse("2006-01-02 03:04:05", datestr[:i], loc)
|
||||
if err == nil {
|
||||
ms, err := strconv.Atoi(datestr[i+1:])
|
||||
if err == nil {
|
||||
return time.Unix(0, t.UnixNano()+int64(ms)*1e6), nil
|
||||
}
|
||||
}
|
||||
return t, err
|
||||
}
|
||||
// hm, lets just swap out comma for period. for some reason go
|
||||
// won't parse it.
|
||||
// 2014-05-11 08:20:13,787
|
||||
ds := []byte(p.datestr)
|
||||
ds[i] = '.'
|
||||
return parseTime(string(ds), loc)
|
||||
case '-', '+':
|
||||
// 03:21:51+00:00
|
||||
p.stateTime = timeOffset
|
||||
@ -1203,6 +1198,7 @@ iterRunes:
|
||||
// 12 Feb 2006, 19:17
|
||||
// 12 Feb 2006, 19:17:22
|
||||
return p.parse()
|
||||
|
||||
case dateDigitWsMolong:
|
||||
// 18 January 2018
|
||||
// 8 January 2018
|
||||
|
@ -116,8 +116,8 @@ func TestInLocation(t *testing.T) {
|
||||
func TestOne(t *testing.T) {
|
||||
time.Local = time.UTC
|
||||
var ts time.Time
|
||||
ts = MustParse("Mon Aug 10 15:44:11 PST-0700 2015")
|
||||
assert.Equal(t, "2015-08-10 22:44:11 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
ts = MustParse("2014-05-11 08:20:13,787")
|
||||
assert.Equal(t, "2014-05-11 08:20:13.787 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC)))
|
||||
}
|
||||
func TestParse(t *testing.T) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user