How can I tell if a local time is non-existent? I'm trying with pytz, but it throws an AmbiguousTimeError, not a NonExistentTimeError.
2013-3-31 02:30 will never happen in Copenhagen due to daylight savings time.
local_tz = timezone('Europe/Copenhagen')
try:
non_e = local_tz.localize(datetime.datetime(2013, 3, 31, 2, 30), is_dst = None)
except pytz.AmbiguousTimeError:
print "AmbiguousTimeError"
It goes to the exception handler. I've tried:
except pytz.NonExistentTimeError: #'module' object has no attribute 'NonExistentTimeError'
except pytz.exceptions.NonExistentTimeError: #'module' object has no attribute 'exceptions'
The user supplies me with a date and time via a form. These are in local time and I need to see whether the dates and times are ok.
I'm using Django with USE_TZ = True
, but I don't think that matters here.