Skip to content

Commit

Permalink
fix: handle DST folded dates with start/end_of
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonyuu committed Jun 14, 2023
1 parent c4e518c commit 76d2eb1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def set(
tz = self.tz

return self.__class__.create(
year, month, day, hour, minute, second, microsecond, tz=tz
year, month, day, hour, minute, second, microsecond, tz=tz, fold=self.fold
)

@property
Expand Down
35 changes: 35 additions & 0 deletions tests/datetime/test_start_end_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,45 @@ def test_start_of_with_transition():
assert d.start_of("day").offset == 7200
assert d.start_of("year").offset == 3600

def test_start_of_on_date_before_transition():
d = pendulum.datetime(2013, 10, 27, 0, 59, 59, tz="UTC").in_timezone("Europe/Paris")
assert d.offset == 7200
assert d.start_of("minute").offset == 7200
assert d.start_of("hour").offset == 7200
assert d.start_of("day").offset == 7200
assert d.start_of("month").offset == 7200
assert d.start_of("year").offset == 3600

def test_start_of_on_date_after_transition():
d = pendulum.datetime(2013, 10, 27, 1, 59, 59, tz="UTC").in_timezone("Europe/Paris")
assert d.offset == 3600
assert d.start_of("minute").offset == 3600
assert d.start_of("hour").offset == 3600
assert d.start_of("day").offset == 7200
assert d.start_of("month").offset == 7200
assert d.start_of("year").offset == 3600

def test_end_of_with_transition():
d = pendulum.datetime(2013, 3, 31, tz="Europe/Paris")
assert d.offset == 3600
assert d.end_of("month").offset == 7200
assert d.end_of("day").offset == 7200
assert d.end_of("year").offset == 3600

def test_end_of_on_date_before_transition():
d = pendulum.datetime(2013, 10, 27, 0, 0, 0, tz="UTC").in_timezone("Europe/Paris")
assert d.offset == 7200
assert d.end_of("minute").offset == 7200
assert d.end_of("hour").offset == 7200
assert d.end_of("day").offset == 3600
assert d.end_of("month").offset == 3600
assert d.end_of("year").offset == 3600

def test_end_of_on_date_after_transition():
d = pendulum.datetime(2013, 10, 27, 1, 0, 0, tz="UTC").in_timezone("Europe/Paris")
assert d.offset == 3600
assert d.end_of("minute").offset == 3600
assert d.end_of("hour").offset == 3600
assert d.end_of("day").offset == 3600
assert d.end_of("month").offset == 3600
assert d.end_of("year").offset == 3600

0 comments on commit 76d2eb1

Please sign in to comment.