8000 Fix calculating remaining time across DST changes by imrivera · Pull Request #9669 · celery/celery · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix calculating remaining time across DST changes #9669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

imrivera
Copy link
Contributor
@imrivera imrivera commented Apr 17, 2025

Description

Fix calculating the remaining time across DST changes.

Python by default uses wall time (not real time) in arithmetic between datetimes with equal non-UTC timezones. For example:

dt1 = datetime(day=10, month=3, year=2019, hour=1, minute=30, tzinfo=ZoneInfo("US/Eastern")  # EST
dt2 = datetime(day=10, month=3, year=2019, hour=3, minute=30, tzinfo=ZoneInfo("US/Eastern")  # EDT
print(f"dt1: {dt1}")
print(f"dt2: {dt2}")
print(f"wall diff: {repr(dt2 - dt1)}")
print(f"real diff: {repr(dt2.astimezone(ZoneInfo("UTC")) - dt1.astimezone(ZoneInfo("UTC")))}")

This will print:

dt1: 2019-03-10 01:30:00-05:00
dt2: 2019-03-10 03:30:00-04:00 
wall diff: datetime.timedelta(seconds=7200)
real diff: datetime.timedelta(seconds=3600)

And in Celery's use case we are interested in the real time, not the wall time.

Interesting blog post about this non-intuitive behavior here

Fixes #9653

@Nusnus Nusnus self-requested a review April 17, 2025 13:46
Copy link
Member
@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!
I’ll review it once the CI finishes

Co 8000 py link
codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.30%. Comparing base (d643c7c) to head (38141c6).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9669   +/-   ##
=======================================
  Coverage   78.30%   78.30%           
=======================================
  Files         153      153           
  Lines       19123    19123           
  Branches     2534     2533    -1     
=======================================
  Hits        14975    14975           
  Misses       3858     3858           
  Partials      290      290           
Flag Coverage Δ
unittests 78.28% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member
@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much @imrivera !
DST issues are really pesky. Nice fix!

@Nusnus Nusnus merged commit f0c7261 into celery:main Apr 17, 2025
342 of 346 checks passed
github-merge-queue bot pushed a commit to Software-Engineering-Jagiellonian/django-celery-frege that referenced this pull request May 29, 2025
Bumps [celery[redis]](https://github.com/celery/celery) from 5.5.1 to
5.5.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/celery/celery/releases">celery[redis]'s
releases</a>.</em></p>
<blockquote>
<h2>v5.5.2</h2>
<h2>What's Changed</h2>
<ul>
<li>Fix calculating remaining time across DST changes by <a
href="https://github.com/imrivera"><code>@​imrivera</code></a> in <a
href="https://redirect.github.com/celery/celery/pull/9669">celery/celery#9669</a></li>
<li>Remove <code>setup_logger</code> from COMPAT_MODULES by <a
href="https://github.com/rconradharris"><code>@​rconradharris</code></a>
in <a
href="https://redirect.github.com/celery/celery/pull/9668">celery/celery#9668</a></li>
<li>Fix mongodb bullet and fix github links in contributions section by
<a
href="https://github.com/jabberwock404"><code>@​jabberwock404</code></a>
in <a
href="https://redirect.github.com/celery/celery/pull/9672">celery/celery#9672</a></li>
<li>Prepare for release: v5.5.2 by <a
href="https://github.com/Nusnus"><code>@​Nusnus</code></a> in <a
href="https://redirect.github.com/celery/celery/pull/9675">celery/celery#9675</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/imrivera"><code>@​imrivera</code></a>
made their first contribution in <a
href="https://redirect.github.com/celery/celery/pull/9669">celery/celery#9669</a></li>
<li><a
href="https://github.com/rconradharris"><code>@​rconradharris</code></a>
made their first contribution in <a
href="https://redirect.github.com/celery/celery/pull/9668">celery/celery#9668</a></li>
<li><a
href="https://github.com/jabberwock404"><code>@​jabberwock404</code></a>
made their first contribution in <a
href="https://redirect.github.com/celery/celery/pull/9672">celery/celery#9672</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/celery/celery/compare/v5.5.1...v5.5.2">https://github.com/celery/celery/compare/v5.5.1...v5.5.2</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/celery/celery/blob/main/Changelog.rst">celery[redis]'s
changelog</a>.</em></p>
<blockquote>
<h1>5.5.2</h1>
<p>:release-date: 2025-04-25
:release-by: Tomer Nosrati</p>
<p>What's Changed</p>
<pre><code>
- Fix calculating remaining time across DST changes
([#9669](celery/celery#9669))
- Remove `setup_logger` from COMPAT_MODULES
([#9668](celery/celery#9668))
- Fix mongodb bullet and fix github links in contributions section
([#9672](celery/celery#9672))
- Prepare for release: v5.5.2
([#9675](celery/celery#9675))
<p>.. _version-5.5.1:
</code></pre></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/celery/celery/commit/e8adf7f0b4b46a710a96448a9a2f40ace03b4533"><code>e8adf7f</code></a>
Prepare for release: v5.5.2 (<a
href="https://redirect.github.com/celery/celery/issues/9675">#9675</a>)</li>
<li><a
href="https://github.com/celery/celery/commit/2287801006accfa0bba5959bfd2143a6825622d7"><code>2287801</code></a>
fix mongodb bullet and fix contribution github links (<a
href="https://redirect.github.com/celery/celery/issues/9672">#9672</a>)</li>
<li><a
href="https://github.com/celery/celery/commit/1aabeecea57f63802f49d43b6cbd11fb3c33a5f0"><code>1aabeec</code></a>
Remove <code>setup_logger</code> from COMPAT_MODULES (<a
href="https://redirect.github.com/celery/celery/issues/9668">#9668</a>)</li>
<li><a
href="https://github.com/celery/celery/commit/f0c726121468f4368cc6d149a6370900d1b0dbf6"><code>f0c7261</code></a>
Fix calculating remaining time across DST changes (<a
href="https://redirect.github.com/celery/celery/issues/9669">#9669</a>)</li>
<li>See full diff in <a
href="https://github.com/celery/celery/compare/v5.5.1...v5.5.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=celery[redis]&package-manager=pip&previous-version=5.5.1&new-version=5.5.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

crontab() schedule executed one hour too late after DST start
2 participants
0