araddon / dateparse

GoLang Parse many date strings without knowing format in advance.
MIT License
2.03k stars 164 forks source link

CET Timezone not honored #113

Closed ca1f closed 3 years ago

ca1f commented 3 years ago

It seems that the CET timezone is not properly detected.

Adding the values Thu, 17 Dec 2020 15:39:13 GMT and Thu, 17 Dec 2020 16:39:13 CET to the example and verifying that these values are pointing to the same time with

t0, _ := time.Parse(time.RFC1123, "Thu, 17 Dec 2020 15:39:13 GMT")
t1, _ := time.Parse(time.RFC1123, "Thu, 17 Dec 2020 16:39:13 CET")
fmt.Println(t0.Equal(t1))

Parsing these values with dateparse.ParseAny yields the following results:

| Thu, 17 Dec 2020 15:39:13 GMT                         | 2020-12-17 15:39:13 +0000 UTC           |
| Thu, 17 Dec 2020 16:39:13 CET                         | 2020-12-17 16:39:13 +0000 UTC           |

These are not the same.

Expected results:

| Thu, 17 Dec 2020 15:39:13 GMT                         | 2020-12-17 15:39:13 +0000 UTC           |
| Thu, 17 Dec 2020 16:39:13 CET                         | 2020-12-17 16:39:13 +1000 CET           |
araddon commented 3 years ago

Thank you for the report!

I did end up pushing a fix for this, however the end result Is still not possibly same as you seek. I was not able to repro results above without overriding time.Local https://play.golang.org/p/EK_VQP5SjTD

./dateparse --timezone="Europe/Amsterdam" "Thu, 17 Dec 2020 16:39:13 CET"

Your Current time.Local zone is PST

Layout String: dateparse.ParseFormat() => Mon, 02 Jan 2006 15:04:05 MST

Your Using time.Local set to location=Europe/Amsterdam CET 

+-------------+---------------------------+-------------------------------+-------------------------------------+
| method      | Zone Source               | Parsed                        | Parsed: t.In(time.UTC)              |
+-------------+---------------------------+-------------------------------+-------------------------------------+
| ParseAny    | time.Local = nil          | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC day=4 |
| ParseAny    | time.Local = timezone arg | 2020-12-17 16:39:13 +0100 CET | 2020-12-17 15:39:13 +0000 UTC day=4 |
| ParseAny    | time.Local = time.UTC     | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC day=4 |
| ParseIn     | time.Local = nil          | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC       |
| ParseIn     | time.Local = timezone arg | 2020-12-17 16:39:13 +0100 CET | 2020-12-17 15:39:13 +0000 UTC       |
| ParseIn     | time.Local = time.UTC     | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC       |
| ParseLocal  | time.Local = nil          | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC       |
| ParseLocal  | time.Local = timezone arg | 2020-12-17 16:39:13 +0100 CET | 2020-12-17 15:39:13 +0000 UTC       |
| ParseLocal  | time.Local = time.UTC     | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC       |
| ParseStrict | time.Local = nil          | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC       |
| ParseStrict | time.Local = timezone arg | 2020-12-17 16:39:13 +0100 CET | 2020-12-17 15:39:13 +0000 UTC       |
| ParseStrict | time.Local = time.UTC     | 2020-12-17 16:39:13 +0000 CET | 2020-12-17 16:39:13 +0000 UTC       |
+-------------+---------------------------+-------------------------------+-------------------------------------+