From 49f9259ee38d07981a58acd3778f9ae8be9565c1 Mon Sep 17 00:00:00 2001 From: Klondike Dragon Date: Tue, 12 Dec 2023 20:18:58 -0700 Subject: [PATCH] Add support for dd[th,nd,st,rd] Month yyyy Incorporate PR https://github.com/araddon/dateparse/pull/128 from https://github.com/krhubert to fix https://github.com/araddon/dateparse/issues/127 --- parseany.go | 6 ++++++ parseany_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/parseany.go b/parseany.go index 1dc0443..74ca494 100644 --- a/parseany.go +++ b/parseany.go @@ -435,6 +435,12 @@ iterRunes: p.stateDate = dateDigitChineseYear case ',': return p, unknownErr(datestr) + case 's', 'S', 'r', 'R', 't', 'T', 'n', 'N': + // 1st January 2018 + // 2nd Jan 2018 23:59 + // st, rd, nd, st + p.stateDate = dateAlphaWsMonthSuffix + i-- default: continue } diff --git a/parseany_test.go b/parseany_test.go index 1a6398f..7940dd6 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -133,6 +133,14 @@ var testInputs = []dateTest{ {in: "June 2nd 2012", out: "2012-06-02 00:00:00 +0000 UTC"}, {in: "June 22nd, 2012", out: "2012-06-22 00:00:00 +0000 UTC"}, {in: "June 22nd 2012", out: "2012-06-22 00:00:00 +0000 UTC"}, + // Incorporate PR https://github.com/araddon/dateparse/pull/128 to fix https://github.com/araddon/dateparse/issues/127 + // dd[th,nd,st,rd] Month yyyy + {in: "1st September 2012", out: "2012-09-01 00:00:00 +0000 UTC"}, + {in: "2nd September 2012", out: "2012-09-02 00:00:00 +0000 UTC"}, + {in: "3rd September 2012", out: "2012-09-03 00:00:00 +0000 UTC"}, + {in: "4th September 2012", out: "2012-09-04 00:00:00 +0000 UTC"}, + {in: "2nd January 2018", out: "2018-01-02 00:00:00 +0000 UTC"}, + {in: "3nd Feb 2018 13:58:24", out: "2018-02-03 13:58:24 +0000 UTC"}, // RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST" {in: "Fri, 03 Jul 2015 08:08:08 MST", out: "2015-07-03 08:08:08 +0000 UTC", zname: "MST"}, {in: "Fri, 03 Jul 2015 08:08:08 CET", out: "2015-07-03 08:08:08 +0000 UTC", zname: "CET"},