Skip to content

Commit

Permalink
support combined datetime format with subseconds (yyyyMMddhhmmss.SSS)
Browse files Browse the repository at this point in the history
Fixes araddon#143

Signed-off-by: Daniel Ferstay <dferstay@splunk.com>
  • Loading branch information
Daniel Ferstay committed Nov 11, 2021
1 parent 266bf7b commit 18b34b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions parseany.go
Expand Up @@ -376,13 +376,15 @@ iterRunes:
p.yearlen = i
p.moi = i + 1
p.setYear()
} else {
} else if i <= 2 {
p.ambiguousMD = true
p.moi = 0
p.molen = i
p.setMonth()
p.dayi = i + 1
}
// else this might be a unixy combined datetime of the form:
// yyyyMMddhhmmss.SSS

case ' ':
// 18 January 2018
Expand Down Expand Up @@ -1947,10 +1949,15 @@ iterRunes:
return p, nil

case dateDigitDot:
// 2014.05
p.molen = i - p.moi
p.setMonth()
return p, nil
if len(datestr) == len("yyyyMMddhhmmss.SSS") { // 18
p.format = []byte("20060102150405.000")
return p, nil
} else {
// 2014.05
p.molen = i - p.moi
p.setMonth()
return p, nil
}

case dateDigitDotDot:
// 03.31.1981
Expand Down
1 change: 1 addition & 0 deletions parseany_test.go
Expand Up @@ -414,6 +414,7 @@ var testInputs = []dateTest{
{in: "2014", out: "2014-01-01 00:00:00 +0000 UTC"},
{in: "20140601", out: "2014-06-01 00:00:00 +0000 UTC"},
{in: "20140722105203", out: "2014-07-22 10:52:03 +0000 UTC"},
{in: "20140722105203.364", out: "2014-07-22 10:52:03.364 +0000 UTC"},
// yymmdd hh:mm:yy mysql log https://github.com/araddon/dateparse/issues/119
// 080313 05:21:55 mysqld started
// 080313 5:21:55 InnoDB: Started; log sequence number 0 43655
Expand Down

0 comments on commit 18b34b0

Please sign in to comment.