Skip to content

fold value behaves differently for different timedelta addition values #853

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
2 tasks done
Mcklmo opened this issue Oct 28, 2024 · 1 comment
Open
2 tasks done

Comments

@Mcklmo
Copy link

Mcklmo commented Oct 28, 2024

  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Windows 11
  • Pendulum version: 3.0.0

Issue

The fold attribute behaves weirdly when adding different timedeltas to a datetime object. Adding minutes changes the fold from 0 to 1. Adding days keeps it at 1.

On the other hand, when setting fold to 0, adding minutes preserves it, and adding days changes it.

It seems like adding minutes forces the fold attribute to be 0 and days forces it to be 1.

import pendulum

year, month, day = 2024, 5, 1
dt = pendulum.datetime(year, month, day, tz="CET")

print(dt.fold)
print(dt.add(minutes=1).fold)
print(dt.add(days=1).fold)

"""Output:
1
0
1
"""


dt = pendulum.datetime(year, month, day, tz="CET").replace(fold=0)

print(dt.fold)
print(dt.add(minutes=1).fold)
print(dt.add(days=1).fold)

"""Output:
0
0
1
"""
@jakobdo
Copy link

jakobdo commented Oct 30, 2024

I have a similar issue.

When working with pendulum and dst, I ran into this issue:

str(pendulum.parse("2024-10-27 02:00:00", tz="Europe/Copenhagen"))
'2024-10-27 02:00:00+01:00'
str(pendulum.parse("2024-10-27 02:00:00", tz="Europe/Copenhagen").subtract(minutes=15))
'2024-10-27 02:45:00+02:00' <-- Why does this end as 02:00 ?
If "2024-10-27 02:00:00" = '2024-10-27 02:00:00+01:00'
I would expect
str(pendulum.parse("2024-10-27 02:00:00", tz="Europe/Copenhagen").subtract(minutes=15)) to be equal = '2024-10-27 01:45:00+01:00'

I can get the expected value using:
str(pendulum.parse("2024-10-27 02:00:00", tz="Europe/Copenhagen").replace(fold=0).subtract(minutes=15))
'2024-10-27 01:45:00+02:00'

But I seems like a "stupid" hack.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants