Fix time code to work in timezones other than UTC, and add tests in multiple timezones (#810)

* Add tests in multiple timezones.

* Fix get_epoch_seconds() for timestamps without timezones.

* Add changelog fragment.

* Pin version for Python 2.6.
This commit is contained in:
Felix Fontein
2024-10-24 20:24:55 +02:00
committed by GitHub
parent 21e344e283
commit feee571bc8
7 changed files with 220 additions and 139 deletions

View File

@@ -83,6 +83,9 @@ if sys.version_info < (3, 3):
return (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 10**6) / 10**6
else:
def get_epoch_seconds(timestamp):
if timestamp.tzinfo is None:
# timestamp.timestamp() is offset by the local timezone if timestamp has no timezone
timestamp = ensure_utc_timezone(timestamp)
return timestamp.timestamp()