From 0935bf14af5801b112aa2f41302f7d747e22f759 Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Wed, 15 Apr 2026 09:10:54 +0800 Subject: [PATCH] fix: preserve location in RetryAmbiguousDateWithSwap retry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When RetryAmbiguousDateWithSwap retries parsing after a "month out of range" error, it called parseTime with time.Local instead of the original location parameter. This causes inconsistent timezones: ParseAny("21/09/2010", RetryAmbiguousDateWithSwap(true)) → 2010-09-21 00:00:00 +0200 CEST (uses time.Local in retry) ParseAny("09/21/2010", RetryAmbiguousDateWithSwap(true)) → 2010-09-21 00:00:00 +0000 UTC (no retry needed) Fix: pass the original loc parameter to the retry parseTime call instead of time.Local, ensuring consistent timezone handling. Fixes #161 --- parseany.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parseany.go b/parseany.go index b9668b2..076f51c 100644 --- a/parseany.go +++ b/parseany.go @@ -250,7 +250,7 @@ func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *par // turn off the retry to avoid endless recursion retryAmbiguousDateWithSwap := RetryAmbiguousDateWithSwap(false) modifiedOpts := append(opts, preferMonthFirst, retryAmbiguousDateWithSwap) - p, err = parseTime(datestr, time.Local, modifiedOpts...) + p, err = parseTime(datestr, loc, modifiedOpts...) } }