Skip to content

fix(datetime.dst): pass Gregorian to tzinfo.dst()#189

Open
5j9 wants to merge 1 commit into
slashmili:v5from
5j9:dst-v5
Open

fix(datetime.dst): pass Gregorian to tzinfo.dst()#189
5j9 wants to merge 1 commit into
slashmili:v5from
5j9:dst-v5

Conversation

@5j9

@5j9 5j9 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Standard timezone libraries and databases expect standard Gregorian datetime objects to resolve DST offsets correctly. Passing a Jalali datetime object (self) causes two major issues:

  1. It results in silent bugs because the database evaluates rules for the Jalali year (e.g., 1405 AD instead of the converted 2026 AD).
  2. It can raise type/attribute errors if strict type-checking is enforced.

This converts the instance to its Gregorian representation using self.togregorian() before passing it to tzinfo.dst().

Also:

  • Removes the outdated TODO comment on the dst method.
  • Adds unit tests using zoneinfo to verify DST calculations for both aware and naive jdatetime instances.

Standard timezone libraries and databases expect standard Gregorian
datetime objects to resolve DST offsets correctly. Passing a Jalali
datetime object (`self`) causes two major issues:
1. It results in silent bugs because the database evaluates rules for
   the Jalali year (e.g., 1405 AD instead of the converted 2026 AD).
2. It can raise type/attribute errors if strict type-checking is enforced.

This converts the instance to its Gregorian representation using
`self.togregorian()` before passing it to `tzinfo.dst()`.

Also:
- Removes the outdated TODO comment on the `dst` method.
- Adds unit tests using zoneinfo to verify DST calculations
  for both aware and naive jdatetime instances.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant