You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
start_of()/end_of() return the previous day or are an hour off when DST changes at midnight #1093
start_of() and end_of() (day, week, month, year, decade, century) keep the fold of the input. When a DST change happens at midnight, the result can be on the wrong day or one hour off.
importpendulum# Cairo skips 00:00-01:00 on 2026-04-24now=pendulum.datetime(2026, 4, 24, 12, tz="UTC").in_timezone("Africa/Cairo") # fold=0, like pendulum.now()now.start_of("day")
# 2026-04-23 23:00:00+02:00 <- the day before# expected 2026-04-24 01:00:00+03:00# so pendulum.today("Africa/Cairo") returns yesterday on that date.# Cairo repeats 23:00-24:00 on 2026-10-29now=pendulum.datetime(2026, 10, 29, 12, tz="UTC").in_timezone("Africa/Cairo")
now.end_of("day").in_tz("UTC")
# 2026-10-29 20:59:59.999999+00:00 <- one hour early# expected 2026-10-29 21:59:59.999999+00:00 (23:59:59.999999+02:00)# Havana repeated 00:00-01:00 on 2012-11-04; default fold=1 picks the second midnightpendulum.datetime(2012, 11, 4, 12, tz="America/Havana").start_of("day")
# 2012-11-04 00:00:00-05:00, expected 2012-11-04 00:00:00-04:00
Same for Beirut, Gaza, Tehran (old rules), Santiago, Asuncion, Havana, Azores and others.
Cause: since #713, DateTime.set() passes fold=self.fold to create(). _start_of_day / _end_of_day / _start_of_month / ... go through set()/at(), so the input's fold decides how 00:00 or 23:59:59.999999 is resolved. With fold=0, a skipped midnight is moved back into the previous day; with fold=1 a repeated midnight picks the later one. The start of a day should be the earliest instant on that date, and the end the latest one.
I checked every zone in tzdata, 1995-2035, a few hours around each transition, with both folds: 1,817 of 148,232 start_of("day")/end_of("day") results are on the wrong date or not the first/last instant of the date.
Activity