Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error messages for NonExistentTimeError and AmbiguousTimeError a bit friendlier #428

Open
niclasmattsson opened this issue Apr 20, 2023 · 0 comments

Comments

@niclasmattsson
Copy link

A colleague and I were baffled today when some machine learning training code crashed with a NonExistentTimeError. Here's an MWE:

julia> ZonedDateTime(DateTime(1982,1,1,0), tz"Europe/Gibraltar")
ERROR: NonExistentTimeError: Local DateTime 1982-01-01T00:00:00 does not exist within Europe/Gibraltar
Stacktrace:
 [1] (::TimeZones.var"#construct#8"{DateTime, VariableTimeZone})(T::Type{Local})
   @ TimeZones C:\Users\niclas\.julia\packages\TimeZones\V28u7\src\types\zoneddatetime.jl:44
 [2] #ZonedDateTime#7
   @ C:\Users\niclas\.julia\packages\TimeZones\V28u7\src\types\zoneddatetime.jl:50 [inlined]
 [3] ZonedDateTime(dt::DateTime, tz::VariableTimeZone)
   @ TimeZones C:\Users\niclas\.julia\packages\TimeZones\V28u7\src\types\zoneddatetime.jl:35
 [4] top-level scope
   @ REPL[90]:1

Constructing the same ZonedDateTime worked just fine for 1980 and 1981, or alternatively for Jan 2 of 1982 instead of Jan 1. I'm sure the explanation is obvious for the package devs but it certainly wasn't for us. Apparently Gibraltar switched time zones in 1982:

https://en.wikipedia.org/wiki/Time_in_Gibraltar

So that particular hour of that year of that time zone doesn't exist, and the error is correct. But it's still inscrutable for those inexperienced with working with time zones. The more common source of this error is the transition to/from daylight savings time, and I noticed there is a hint for that case in the help string:

help?> NonExistentTimeError
search: NonExistentTimeError

  NonExistentTimeError(local_datetime, timezone)

  The provided local datetime is does not exist within the specified timezone. Typically occurs on daylight saving time transitions which "spring forward" causing an hour long period to be skipped.

But it's not obvious either that you could get that hint from the docs of the error constructor function.

Proposal

I suggest making two small changes. First, add a hint pointer in the error message for NonExistentTimeError, so something like this:

ERROR: NonExistentTimeError: Local DateTime 1982-01-01T00:00:00 does not exist within Europe/Gibraltar.
Type ?NonExistentTimeError for some possible explanations.

Second, expand the hints in that docstring:

  NonExistentTimeError(local_datetime, timezone)

  The provided local datetime does not exist within the specified timezone. Typically occurs on daylight saving time transitions which "spring forward" causing an hour long period to be skipped, or in rare instances when a region permanently switches time zones.

(Also note there is a superfluous "is" in the original string.) Similar changes should also be made to AmbiguousTimeError. Are there other possible explanations that could be appended here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant