feat(time): add optional weekday parameter to naturalday (#102) - #377
Open
harmehak0173 wants to merge 2 commits into
Open
feat(time): add optional weekday parameter to naturalday (#102)#377harmehak0173 wants to merge 2 commits into
harmehak0173 wants to merge 2 commits into
Conversation
Mukller
approved these changes
Aug 23, 2026
Mukller
left a comment
There was a problem hiding this comment.
Verified locally on the PR branch (Python 3.13, editable install), frozen at Wed 2026-08-12:
Full boundary matrix for naturalday(d, weekday=True):
| offset | result |
|---|---|
| today / yesterday / tomorrow | today / yesterday / tomorrow (existing behavior untouched) |
| -2d | last Monday |
| -6d | last Thursday |
| -7d | falls back to format (Aug 05) — correct out-of-range boundary |
| +2d | this Friday |
| +6d | this Tuesday |
| +7d | falls back to format — correct |
weekday=False (default) |
identical to master for all inputs |
Master control: weekday=True raises TypeError: unexpected keyword argument — purely additive, zero risk to existing callers. The new strings are wrapped in _() so they flow through humanize's i18n catalog like the rest of the module.
pytest tests/test_time.py — 383 passed, including the new freeze_time-based tests.
Two non-blocking notes:
- Boundary asymmetry is intentional-looking but worth a docs sentence: past side covers [-6, -2] and future [2, +6], while ±1 are absorbed by yesterday/tomorrow and ±7+ fall through. The docstring documents it accurately; just make sure the README example (if added later) matches.
%Auses locale-aware day names — consistent with the rest of humanize, but non-English locales will produce e.g."last понедельник"unless translations coverlast %s/this %s. Worth one line in the PR description so translators know new keys exist.
Feature is coherent and well-tested. Approving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Adds an optional
weekday: bool = Falseparameter tonaturalday()to format dates within a 6-day window using weekday names (e.g."this Saturday","last Sunday") (#102).Changes Implemented
naturalday(value, format="%b %d", *, weekday=False)insrc/humanize/time.py:_("this %s") % day_name(e.g."this Saturday")._("last %s") % day_name(e.g."last Sunday").today,tomorrow, andyesterdayremain unchanged.test_naturalday_weekdayintests/test_time.py.Testing
pytest tests/test_time.py: All 384 tests passed.