Description
Currently it is possible to use DateTimeValidator with datetime ranges but without setting local_timezone. This can lead to problems when either the input datetime is a local datetime or the datetime range boundaries are local datetimes (comparing local datetimes with timezoned datetimes will raise a TypeError).
Currently there is this note in the class documentation:
Note: When using datetime ranges, make sure not to mix datetimes that have timezones with local datetimes because those comparisons will raise
TypeError
exceptions. It's recommended either to use only datetimes with defined timezones (for both input values and the boundaries of the datetime ranges), or to specify the 'local_timezone' parameter (which will also be used to determine the timezone of the range boundary datetimes if they do not specify timezones themselves).
Instead of just warning in the documentation, it might be a good idea to catch these edge cases already at validator creation (i.e. in __init__()
): If the DateTimeFormat is one that allows local datetimes AND a range is defined AND local_timezone is NOT set: Raise an InvalidValidatorOptionException
.
Not sure though whether there might be usecases where you don't want to define a local_timezone (e.g. you only allow local datetimes (DateTimeFormat.LOCAL_ONLY
) and you define a range that has local datetimes as boundaries too).