JuliaTime / TimeZones.jl

IANA time zone database access for the Julia programming language
Other
85 stars 54 forks source link

parsing CEST #346

Open cadoubs opened 3 years ago

cadoubs commented 3 years ago

From the documentation:

julia> Dates.format(zdt, "yyyy-mm-dd HH:MM ZZZ")
"2015-08-06 22:25 CEST"

But parsing in the other side returns an error:

julia> ZonedDateTime("2015-08-06 22:25 CEST",DateFormat("yyyy-mm-dd HH:MM Z"))
ERROR: ArgumentError: Unable to parse string "2015-08-06 22:25 CEST" using format dateformat"yyyy-mm-dd HH:MM Z". Unable to parse date time. Expected directive DatePart(Z) at char 18
...

Whereas with Europe/Paris (which is normally equivalent to CEST), it works:

julia> ZonedDateTime("2015-08-06 22:25 Europe/Paris",DateFormat("yyyy-mm-dd HH:MM Z"))
2015-08-06T22:25:00+02:00

Any workaround except replace before applying ZonedDateTime ?

omus commented 3 years ago

Unfortunately this needs to be handled on a case-by-case basis as time zone abbreviations are not guaranteed to be unique. What should be done however is allowing end users to pass in a dict which maps time zone abbreviations to time zone instances.

cadoubs commented 3 years ago

Thank you for your reply.

The parse function could detect possible multiple results and display an error in this case. The best example is CST (Central/China/Cuba Standard Time).

Passing a known location information as reference for users (North America or Central America, Asia , Caribbean) could be easy way (for users) to determine Time Zone in case of doubt. The suggested dictionary is also an interesting possibility.