Skip to content

fold value behaves differently for different timedelta addition values #853

Open
@Mcklmo

Description

@Mcklmo
  • 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
"""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions