Skip to content

Commit df9ae2e

Browse files
Incorporate support for yyyymmddhhmmss.SSS
Incorporate PR araddon#144 from https://github.com/dferstay to fix araddon#143
1 parent fc278d3 commit df9ae2e

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

parseany.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ iterRunes:
400400
if !p.setYear() {
401401
return p, unknownErr(datestr)
402402
}
403-
} else {
403+
} else if i <= 2 {
404404
p.ambiguousMD = true
405405
if p.preferMonthFirst {
406406
if p.molen == 0 {
@@ -421,6 +421,8 @@ iterRunes:
421421
}
422422
}
423423
}
424+
// else this might be a unixy combined datetime of the form:
425+
// yyyyMMddhhmmss.SSS
424426

425427
case ' ':
426428
// 18 January 2018
@@ -2128,12 +2130,17 @@ iterRunes:
21282130
return p, nil
21292131

21302132
case dateDigitDot:
2131-
// 2014.05
2132-
p.molen = i - p.moi
2133-
if !p.setMonth() {
2134-
return p, unknownErr(datestr)
2133+
if len(datestr) == len("yyyyMMddhhmmss.SSS") { // 18
2134+
p.setEntireFormat([]byte("20060102150405.000"))
2135+
return p, nil
2136+
} else {
2137+
// 2014.05
2138+
p.molen = i - p.moi
2139+
if !p.setMonth() {
2140+
return p, unknownErr(datestr)
2141+
}
2142+
return p, nil
21352143
}
2136-
return p, nil
21372144

21382145
case dateDigitDotDot:
21392146
// 03.31.1981

parseany_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ var testInputs = []dateTest{
418418
{in: "2013 May 02 11:37:55", out: "2013-05-02 11:37:55 +0000 UTC"},
419419
{in: "2013 June 02 11:37:55", out: "2013-06-02 11:37:55 +0000 UTC"},
420420
{in: "2013 December 02 11:37:55", out: "2013-12-02 11:37:55 +0000 UTC"},
421+
// https://github.com/araddon/dateparse/issues/143
422+
{in: "20140722105203.364", out: "2014-07-22 10:52:03.364 +0000 UTC"},
421423
// yyyy-mm-dd hh:mm:ss,000
422424
{in: "2014-05-11 08:20:13,787", out: "2014-05-11 08:20:13.787 +0000 UTC"},
423425
// yyyy-mm-dd hh:mm:ss +0000

0 commit comments

Comments
 (0)