python-libfaketime icon indicating copy to clipboard operation
python-libfaketime copied to clipboard

Support offset-only tzinfo objects

Open danpalmer opened this issue 5 years ago • 0 comments

It's possible for a tzinfo object to only have an offset and no named timezone. For example:

>>> dateutil.parser.parse('2020-04-12 00:26 +1')
datetime.datetime(2020, 4, 12, 0, 26, tzinfo=tzoffset(None, 3600))

Because these don't have a name, we can't set the TZ environment variable with the name straight from tzname or zone (see #58 for some context on that difference).

I'd suggest that a good solution might be to use the same behaviour as already exists here

self.timezone_str = 'Etc/GMT{0:+}'.format(-tz_offset)

It may be necessary to support both the tz_offset argument and the offset in the datetime_spec.tzinfo in the case that it's a datetime. It may also be necessary to combine these, but I'm not quite sure what the desired behaviour is when both a tz_offset and a timezone-aware datetime are provided.

danpalmer avatar Apr 11 '20 23:04 danpalmer