Add support for dd-month-year format

This commit is contained in:
Klondike Dragon 2023-12-18 23:14:58 -07:00
parent 7a3c923820
commit 65e6e8d1a9
2 changed files with 14 additions and 1 deletions

View File

@ -635,9 +635,22 @@ iterRunes:
switch r {
case '-', '\u2212':
p.molen = i - p.moi
// Must be a valid short or long month
if p.molen == 3 {
p.set(p.moi, "Jan")
p.yeari = i + 1
p.stateDate = dateDigitDashAlphaDash
} else {
possibleFullMonth := strings.ToLower(p.datestr[p.moi:(p.moi + p.molen)])
if i > 3 && isMonthFull(possibleFullMonth) {
p.fullMonth = possibleFullMonth
p.yeari = i + 1
p.stateDate = dateDigitDashAlphaDash
} else {
return p, p.unknownErr(datestr)
}
}
default:
if !unicode.IsLetter(r) {
return p, p.unknownErr(datestr)

View File

@ -403,7 +403,7 @@ var testInputs = []dateTest{
{in: "15-Jan-2017", out: "2017-01-15 00:00:00 +0000 UTC"},
{in: "28-Feb-02 15:16:17", out: "2002-02-28 15:16:17 +0000 UTC"},
{in: "15-Jan-18 15:16:17", out: "2018-01-15 15:16:17 +0000 UTC"},
{in: "15-Jan-2017 15:16:17", out: "2017-01-15 15:16:17 +0000 UTC"},
{in: "15-September-2017 15:16:17", out: "2017-09-15 15:16:17 +0000 UTC"},
// dd-mm-yy (digit month - potentially ambiguous) - https://github.com/araddon/dateparse/issues/139
{in: "28-02-02", out: "2002-02-28 00:00:00 +0000 UTC"},
{in: "15-01-18", out: "2018-01-15 00:00:00 +0000 UTC"},