Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/docs/fluent_helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ converts the time in the appropriate timezone.
```python
>>> import pendulum

>>> dt = pendulum.datetime(2013, 3, 31, 2, 30)
>>> print(dt)
>>> dt0 = pendulum.datetime(2013, 3, 31, 2, 30)
>>> print(dt0)
'2013-03-31T02:30:00+00:00'

>>> dt = dt.set(tz='Europe/Paris')
>>> # Paris started DST on that exact day, so 2h30 local time doesn't exist. It immediately rolls over to 3h30.
>>> dt = dt0.set(tz='Europe/Paris')
>>> print(dt)
'2013-03-31T03:30:00+02:00'

>>> dt = dt.in_tz('Europe/Paris')
>>> dt = dt0.in_tz('Europe/Paris')
>>> print(dt)
'2013-03-31T04:30:00+02:00'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something weird is going on here. How is this possible that dt0.set(tz=...) produces different result than dt0.in_tz(...) for the same timezone?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_tz converts the time to the new timezone. set normally doesn't convert the time, just sets the timezone, but presumably when the time is invalid in the new time zone it has to change it to a valid one.


>>> dt = dt.set(tz='Europe/Paris').set(tz='UTC')
>>> dt = dt0.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')
>>> dt = dt0.in_tz('Europe/Paris').in_tz('UTC')
>>> print(dt)
'2013-03-31T02:30:00+00:00'
```