araddon / dateparse

GoLang Parse many date strings without knowing format in advance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different timezone used with dateparse.RetryAmbiguousDateWithSwap(true) option.

jozuenoon opened this issue · comments

When running the below test time zone is not consistent:

func TestDateParseOptions(t *testing.T) {
	t0, err := dateparse.ParseAny("21/09/2010", dateparse.RetryAmbiguousDateWithSwap(true))
	require.NoError(t, err)

	t1, err := dateparse.ParseAny("09/21/2010", dateparse.RetryAmbiguousDateWithSwap(true))
	require.NoError(t, err)

	require.Equal(t, t0, t1)
}

   -(time.Time) 2010-09-21 00:00:00 +0200 CEST
   +(time.Time) 2010-09-21 00:00:00 +0000 UTC

I guess this is due to this line (below) using time.Local instead of the loc variable. If anyone can guide me if this is somehow intentional or can be changed (I can create a merge request).

p, err = parseTime(datestr, time.Local, modifiedOpts...)

@jozuenoon -- this bug is fixed in the fork of this package https://pkg.go.dev/github.com/itlightning/dateparse (we're trying to maintain this package) -- I verified that your example test case already passes in the forked package.