[New-bugs-announce] [issue37642] timezone allows no offset from range (23:59, 24:00)

Jörn Heissler report at bugs.python.org
Sun Jul 21 07:41:24 EDT 2019


New submission from Jörn Heissler <launchpad at joern.heissler.de>:

https://bugs.python.org/issue5288 changed datetime.timezone to accept sub-minute offsets.

The C implementation allows offsets from range (23:59, 24:00) while the python implementation does not:

# C
>>> timezone(timedelta(seconds=86399))
datetime.timezone(datetime.timedelta(seconds=86399))

# Python
>>> timezone(timedelta(seconds=86399))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cpython/Lib/datetime.py", line 2194, in __new__
    raise ValueError("offset must be a timedelta "
ValueError: offset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24).

This is because _maxoffset is defined as timedelta(hours=23, minutes=59)

Second issue: The (undocumented) "min" and "max" attributes (both C and python) show 23:59
even though the C implementation can get closer to 24:00.
Should this be changed to timezone(timedelta(seconds=86399, microseconds=999999))?


(Same applies to the minimums)

----------
components: Library (Lib)
messages: 348237
nosy: joernheissler
priority: normal
severity: normal
status: open
title: timezone allows no offset from range (23:59, 24:00)
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37642>
_______________________________________


More information about the New-bugs-announce mailing list