mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-13 05:06:36 +08:00
support ":" as separator for fractional seconds
Fixes #137 Signed-off-by: Daniel Ferstay <dferstay@splunk.com>
This commit is contained in:
parent
6b43995a97
commit
cf0ec3c54d
23
parseany.go
23
parseany.go
@ -1173,8 +1173,10 @@ iterRunes:
|
|||||||
}
|
}
|
||||||
switch r {
|
switch r {
|
||||||
case ',':
|
case ',':
|
||||||
// hm, lets just swap out comma for period. for some reason go
|
// swap out comma for period.
|
||||||
// won't parse it.
|
// Newer versions of Go support comma as a separator, but colon is still unsupported
|
||||||
|
// https://go-review.googlesource.com/c/go/+/300996
|
||||||
|
//
|
||||||
// 2014-05-11 08:20:13,787
|
// 2014-05-11 08:20:13,787
|
||||||
ds := []byte(p.datestr)
|
ds := []byte(p.datestr)
|
||||||
ds[i] = '.'
|
ds[i] = '.'
|
||||||
@ -1250,18 +1252,11 @@ iterRunes:
|
|||||||
p.seci = i + 1
|
p.seci = i + 1
|
||||||
p.minlen = i - p.mini
|
p.minlen = i - p.mini
|
||||||
} else if p.seci > 0 {
|
} else if p.seci > 0 {
|
||||||
// 18:31:59:257 ms uses colon, wtf
|
// 18:31:59:257 ms is separated with a colon
|
||||||
p.seclen = i - p.seci
|
// swap out the colon for a period and re-parse
|
||||||
p.set(p.seci, "05")
|
ds := []byte(p.datestr)
|
||||||
p.msi = i + 1
|
ds[i] = '.'
|
||||||
|
return parseTime(string(ds), loc, opts...)
|
||||||
// gross, gross, gross. manipulating the datestr is horrible.
|
|
||||||
// https://github.com/araddon/dateparse/issues/117
|
|
||||||
// Could not get the parsing to work using golang time.Parse() without
|
|
||||||
// replacing that colon with period.
|
|
||||||
p.set(i, ".")
|
|
||||||
datestr = datestr[0:i] + "." + datestr[i+1:]
|
|
||||||
p.datestr = datestr
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case timeOffset:
|
case timeOffset:
|
||||||
|
@ -384,6 +384,7 @@ var testInputs = []dateTest{
|
|||||||
{in: "2016-06-21T19:55+0130", out: "2016-06-21 18:25:00 +0000 UTC"},
|
{in: "2016-06-21T19:55+0130", out: "2016-06-21 18:25:00 +0000 UTC"},
|
||||||
// yyyy-mm-ddThh:mm:ss:000+0000 - weird format with additional colon in front of milliseconds
|
// yyyy-mm-ddThh:mm:ss:000+0000 - weird format with additional colon in front of milliseconds
|
||||||
{in: "2012-08-17T18:31:59:257+0100", out: "2012-08-17 17:31:59.257 +0000 UTC"}, // https://github.com/araddon/dateparse/issues/117
|
{in: "2012-08-17T18:31:59:257+0100", out: "2012-08-17 17:31:59.257 +0000 UTC"}, // https://github.com/araddon/dateparse/issues/117
|
||||||
|
{in: "2012-08-17T18:31:59:257", out: "2012-08-17 18:31:59.257 +0000 UTC"}, // https://github.com/araddon/dateparse/issues/137
|
||||||
|
|
||||||
// yyyy-mm-ddThh:mm:ssZ
|
// yyyy-mm-ddThh:mm:ssZ
|
||||||
{in: "2009-08-12T22:15Z", out: "2009-08-12 22:15:00 +0000 UTC"},
|
{in: "2009-08-12T22:15Z", out: "2009-08-12 22:15:00 +0000 UTC"},
|
||||||
|
Loading…
Reference in New Issue
Block a user