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