araddon / dateparse

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

Some forms of PM indicator combined with time zone don't work #149

Open klondikedragon opened 2 years ago

klondikedragon commented 2 years ago

This is a very helpful package, thank you!

Parsing 2018-09-30 09:09:09PM EST will produce a correct result (the same as 2018-10-01T01:09:09Z), but 2018-09-30 09:09:09 PM EST will be incorrect (it recognizes the PM but not the time zone -- it produces the time value of 2018-09-30T21:09:09Z).

klondikedragon commented 2 years ago

It also looks like it doesn't properly recognize time zones like PMDT, PMST, and AMT where the time zone name shares the same prefix as PM/AM. (e.g., 2018-09-30 21:09:09 PMDT or 2018-09-30 21:09:09 PM PMDT or 2018-09-30 21:09:09 PM AMT). It looks like when it hits the first P it goes into the timeWsAMPMMaybe state, but then when it hits the M it thinks that it is definitely an AM/PM. At that point it could potentially 'look ahead' at the next rune and if it isn't the end and it's still an alpha character then assume it's a time zone, etc. https://github.com/araddon/dateparse/blob/master/parseany.go#L1397