Given a list of pytz.timezone
objects, and a start
datetime
and end
datetime
defining a range of several months, how do you figure out which timezone has the most-negative UTC offset of all the timezones across the range?
Put another way, find the point in the range at which one of the timezones has a lower UTC offset than any other timezone at any other point in the range, and return the UTC offset.
Ignoring Daylight Saving Time, this is relatively simple: use a method like this to get the UTC offset of each of the timezones in turn for an arbitrary point in the range, and keep the lowest on each iteration.
Taking DST into account makes this more complicated, because you need to care about whether or not the time range contains DST for any of the geographic areas associated with the given timezones. It seems like this is not an officially supported use case for pytz
, and that backports.zoneinfo
doesn't either but might make it slightly easier.
What might the implementation of this function look like?
def _get_most_utcnegative_timezone(timezones, range_start, range_end):
pass