FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159714: Fix ZoneInfo Julian day 59 in leap years by pganssle · Pull Request #159721 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 27 additions & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,33 @@ def _add():
(datetime(2020, 12, 31, 23, 59, 59, 999999), AAA, NORMAL),
)

@call
def _add():
# Julian days 58, 59 and 60 always mean February 27, February 28
# and March 1, including in leap years.
AAA = ZoneOffset("AAA", ZERO)
BBB = ZoneOffset("BBB", ONE_H, ONE_H)

for start, end, start_date, end_date in (
(58, 59, (2, 27), (2, 28)),
(59, 60, (2, 28), (3, 1)),
):
tzstr = f"AAA0BBB,J{start}/12,J{end}/12"
cases[tzstr] = []
for year in (2019, 2020, 2000, 2100):
start_dt = datetime(year, *start_date, 12)
end_dt = datetime(year, *end_date, 12)
cases[tzstr].extend((
(start_dt - timedelta(seconds=1), AAA, NORMAL),
(start_dt, AAA, GAP),
(start_dt.replace(fold=1), BBB, GAP),
(start_dt + ONE_H, BBB, NORMAL),
(end_dt - ONE_H - timedelta(seconds=1), BBB, NORMAL),
(end_dt - ONE_H, BBB, FOLD),
((end_dt - ONE_H).replace(fold=1), AAA, FOLD),
(end_dt, AAA, NORMAL),
))

@call
def _add():
# Taken from America/Godthab, this rule has a transition on the
Expand Down
2 changes: 1 addition & 1 deletion Lib/zoneinfo/_zoneinfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def year_to_epoch(self, year):
days_before_year = _post_epoch_days_before_year(year)

d = self.d
if self.julian and d >= 59 and calendar.isleap(year):
if self.julian and d >= 60 and calendar.isleap(year):
d += 1

epoch = (days_before_year + d) * 86400
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :class:`zoneinfo.ZoneInfo` interpreting the Julian day rule ``J59`` as
February 29 in leap years instead of February 28.
2 changes: 1 addition & 1 deletion Modules/_zoneinfo.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ dayrule_year_to_timestamp(TransitionRuleType *base_self, int year)
// you would use a Julian day, e.g. J91 always refers to April 1st and J365
// always refers to December 31st.
uint16_t day = self->day;
if (self->julian && day >= 59 && is_leap_year(year)) {
if (self->julian && day >= 60 && is_leap_year(year)) {
day += 1;
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL