Skip to content
/ django Public

Fixed #36747 -- Added support for parsing weeks in django.utils.dateparse.parse_duration().#20295

Merged
jacobtylerwalls merged 1 commit intodjango:mainfrom
varunkasyap:ticket-36747
Dec 17, 2025
Merged

Fixed #36747 -- Added support for parsing weeks in django.utils.dateparse.parse_duration().#20295
jacobtylerwalls merged 1 commit intodjango:mainfrom
varunkasyap:ticket-36747

Conversation

@varunkasyap
Copy link
Copy Markdown
Contributor

@varunkasyap varunkasyap commented Nov 22, 2025

Trac ticket number

ticket-36747

Branch description

Added support for parsing weeks in ISO 8601 duration strings (e.g., 'P4W') within django.utils.dateparse.parse_duration(). Previously, this would return None.

This PR also updates the docstrings and documentation to explicitly clarify that while ISO 8601 duration parsing is supported, years (Y) and months (M) remain unsupported

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@varunkasyap varunkasyap force-pushed the ticket-36747 branch 2 times, most recently from 456d0d4 to 6c6d2e3 Compare November 22, 2025 12:34
@varunkasyap varunkasyap changed the title Fixed #36747 -- Added support for parsing weeks in ISO 8601 durations. Fixed #36747 -- Added support for parsing weeks in django.utils.dateparse.parse_duration(). Nov 22, 2025
Copy link
Copy Markdown
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks @varunkasyap 👍 .

I just reclassified this to a new feature on Trac, could you add some docs?

@varunkasyap
Copy link
Copy Markdown
Contributor Author

varunkasyap commented Dec 17, 2025

Hi @jacobtylerwalls, thanks for the review.

For the documentation, are we targeting Django 6.1?

this is how my changes look like:

Release notes:
image

Utils page:
image

Copy link
Copy Markdown
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks for the updates ⭐

I pushed tiny edits to docs.

Comment on lines +152 to +153
ISO 8601 duration parsing now supports weeks (``PnW``). Years (``Y``) and
months (``M``) remain unsupported.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll move some of this into the text above. The rule of thumb is that the versionchanged directive shouldn't contain any information we want to keep forever, as when 6.1 goes EOL, we drop this whole directive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, make sure to indent.

* :func:`django.utils.dateparse.parse_duration` now supports ISO 8601 durations
expressed in weeks (``PnW``). Years (``Y``) and months (``M``) remain
unsupported as they cannot be represented by ``datetime.timedelta``
(:ticket:`36747`).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ticket numbers only necessary for regressions in patch release notes.

~~~~~~~~~

* ...
* :func:`django.utils.dateparse.parse_duration` now supports ISO 8601 durations
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using ~django helps reduce the verbosity of the link text.

@github-actions
Copy link
Copy Markdown

📊 Coverage Report for Changed Files

-------------
Diff Coverage
Diff: origin/main...HEAD, staged and unstaged changes
-------------
No lines with coverage information in this diff.
-------------


Note: Missing lines are warnings only. Some lines may not be covered by SQLite tests as they are database-specific.

For more information about code coverage on pull requests, see the contributing documentation.

@jacobtylerwalls jacobtylerwalls merged commit 0d8548e into django:main Dec 17, 2025
28 of 43 checks passed
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