pendulum
pendulum copied to clipboard
DateTime().set(tz=...) tz keyword return wrong value
import pendulum
dt = pendulum.datetime(2013, 3, 31, 2, 30)
print(dt)
# '2013-03-31T02:30:00+00:00'
print(dt.set(tz='Europe/Paris'))
# '2013-03-31T03:30:00+02:00' bug?
print(dt.set(tz='Europe/Paris'))
need to return '2013-03-31T02:30:00+02:00', something wrong happen
Hi.
I noticed this bug, and even its presence in the documentation.
https://pendulum.eustace.io/docs/
You can also modify the timezone.
>>> dt.set(tz='Europe/London')
Setting the timezone just modifies the timezone information without making any conversion,
while in_timezone() (or in_tz()) converts the time in the appropriate timezone.
>>> import pendulum
>>> dt = pendulum.datetime(2013, 3, 31, 2, 30)
>>> print(dt)
'2013-03-31T02:30:00+00:00'
>>> dt = dt.set(tz='Europe/Paris')
>>> print(dt)
'2013-03-31T03:30:00+02:00'
>>> dt = dt.in_tz('Europe/Paris')
>>> print(dt)
'2013-03-31T04:30:00+02:00'
>>> dt = dt.set(tz='Europe/Paris').set(tz='UTC')
>>> print(dt)
'2013-03-31T03:30:00+00:00'
>>> dt = dt.in_tz('Europe/Paris').in_tz('UTC')
>>> print(dt)
'2013-03-31T02:30:00+00:00'
That makes no sense to me, or something extra (dst related) is happening that is not documented.
I believe this is a critical issue, and either it documentation is wrong, or the code is wrong. Because the two do not agree what set()
is doing.
- pendulum==2.1.2
- Python 3.9.6
- Linux, Fedora 34
Oh. I see. This is really convoluted example. 2013-03-03 2:30 doesn't exist in Europe/Paris, due the DST transition, and default rule being POST_TRANSITION.
The documentation for individual functions like set
is not quite clear about this, and you are forced to read entire documentation to really get this example.