From df9ae2e32a78ca70fd81941021477382ad6ec27c Mon Sep 17 00:00:00 2001 From: Klondike Dragon Date: Tue, 12 Dec 2023 23:19:35 -0700 Subject: [PATCH] Incorporate support for yyyymmddhhmmss.SSS Incorporate PR https://github.com/araddon/dateparse/pull/144 from https://github.com/dferstay to fix https://github.com/araddon/dateparse/issues/143 --- parseany.go | 19 +++++++++++++------ parseany_test.go | 2 ++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/parseany.go b/parseany.go index 5fabaca..ab38784 100644 --- a/parseany.go +++ b/parseany.go @@ -400,7 +400,7 @@ iterRunes: if !p.setYear() { return p, unknownErr(datestr) } - } else { + } else if i <= 2 { p.ambiguousMD = true if p.preferMonthFirst { if p.molen == 0 { @@ -421,6 +421,8 @@ iterRunes: } } } + // else this might be a unixy combined datetime of the form: + // yyyyMMddhhmmss.SSS case ' ': // 18 January 2018 @@ -2128,12 +2130,17 @@ iterRunes: return p, nil case dateDigitDot: - // 2014.05 - p.molen = i - p.moi - if !p.setMonth() { - return p, unknownErr(datestr) + if len(datestr) == len("yyyyMMddhhmmss.SSS") { // 18 + p.setEntireFormat([]byte("20060102150405.000")) + return p, nil + } else { + // 2014.05 + p.molen = i - p.moi + if !p.setMonth() { + return p, unknownErr(datestr) + } + return p, nil } - return p, nil case dateDigitDotDot: // 03.31.1981 diff --git a/parseany_test.go b/parseany_test.go index fc1938a..d78ef05 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -418,6 +418,8 @@ var testInputs = []dateTest{ {in: "2013 May 02 11:37:55", out: "2013-05-02 11:37:55 +0000 UTC"}, {in: "2013 June 02 11:37:55", out: "2013-06-02 11:37:55 +0000 UTC"}, {in: "2013 December 02 11:37:55", out: "2013-12-02 11:37:55 +0000 UTC"}, + // https://github.com/araddon/dateparse/issues/143 + {in: "20140722105203.364", out: "2014-07-22 10:52:03.364 +0000 UTC"}, // yyyy-mm-dd hh:mm:ss,000 {in: "2014-05-11 08:20:13,787", out: "2014-05-11 08:20:13.787 +0000 UTC"}, // yyyy-mm-dd hh:mm:ss +0000