Skip to content

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

Open
5j9 wants to merge 1 commit into
slashmili:mainfrom
5j9:dst
Open

fix(datetime.dst): pass Gregorian to tzinfo.dst()#188
5j9 wants to merge 1 commit into
slashmili:mainfrom
5j9:dst

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.
@slashmili

Copy link
Copy Markdown
Owner

@5j9 Thanks! Any chance we could backport this to v6?

@slashmili

Copy link
Copy Markdown
Owner

I meant to version v5!

@5j9

5j9 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@5j9 Thanks! Any chance we could backport this to v6?

Hi @slashmili,

Since there isn't a dedicated maintenance branch for v6 (and releases like v6.0.1 are tagged directly off main), I assume you don't mean cherry-picking for another branch. But if you're asking whether it's okay to release this as a 6.x version, then yes — I believe it can be released as v6.0.2, since it qualifies as a fix (in the conventional-commits sense) and we're currently on v6.0.1.

@5j9

5j9 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

I meant to version v5!

Oh, sure. I'll create v5 branch and cherry-pick it there.

@5j9

5j9 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

I've created a new branch dst-v5 based on the v5.3.0 tag (ea119aa) and cherry-picked the fix onto it. If you can create a v5 branch on the upstream repository (here), I'll be able to open a new PR.

@slashmili

Copy link
Copy Markdown
Owner

Done! I created v5 branch

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.

2 participants