Skip to content

Commit dd82e15

Browse files
authored
Refactor molad datetime handling and DST adjustments
1 parent f34ae1f commit dd82e15

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

custom_components/yidcal/yidcal_lib/helper.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,32 +304,37 @@ def get_actual_molad(self, today: datetime.date) -> Molad:
304304
if molad_date > first_of_month:
305305
molad_date -= timedelta(days=7)
306306

307-
# 5) Build a tz-aware datetime in Jerusalem time
308-
jer_tz = ZoneInfo("Asia/Jerusalem")
309-
jer_dt = datetime(
307+
# 5) Build a naive datetime with the raw molad time from pyluach.
308+
# pyluach returns the traditional announcement time (no timezone).
309+
# Communities adjust for their own DST: when local clocks spring
310+
# forward, add 1 hour so the announced time matches the clock.
311+
molad_dt = datetime(
310312
molad_date.year,
311313
molad_date.month,
312314
molad_date.day,
313315
ann["hour"],
314316
ann["minutes"],
315-
tzinfo=jer_tz,
316317
)
317318

318-
# pyluach gives you “Jerusalem standard” — if that date is in DST, add it
319-
dst = jer_dt.dst()
319+
# Check if the user's local timezone has DST active on the molad date
320+
local_dt = molad_dt.replace(tzinfo=self.tz)
321+
dst = local_dt.dst()
320322
if dst:
321-
jer_dt += dst
323+
molad_dt += dst
322324

323-
# 6) Format into 12-hour + chalakim (use local time)
324-
h24 = jer_dt.hour
325-
minute = jer_dt.minute
325+
# 6) Format into 12-hour + chalakim
326+
h24 = molad_dt.hour
327+
minute = molad_dt.minute
326328
parts = ann["parts"]
327329
ampm = "am" if h24 < 12 else "pm"
328330
h12 = h24 % 12 or 12
329-
dayname = self.get_day_of_week(jer_dt.date())
331+
dayname = self.get_day_of_week(molad_dt.date())
330332
friendly = f"{dayname}, {h12}:{minute:02d} {ampm} and {parts} chalakim"
331333

332-
return Molad(dayname, h12, minute, ampm, parts, friendly, jer_dt.date(), jer_dt)
334+
# Store tz-aware datetime for the Molad object
335+
molad_dt = molad_dt.replace(tzinfo=self.tz)
336+
337+
return Molad(dayname, h12, minute, ampm, parts, friendly, molad_dt.date(), molad_dt)
333338

334339
def get_molad(self, today: datetime.date) -> MoladDetails:
335340
"""

0 commit comments

Comments
 (0)