Skip to content

weekday: ignore the weekday when an explicit date is given - #335

Open
sap1110 wants to merge 1 commit into
uutils:mainfrom
sap1110:fix-weekday-with-explicit-date
Open

sap1110 wants to merge 1 commit into
uutils:mainfrom
sap1110:fix-weekday-with-explicit-date

Conversation

@sap1110

@sap1110 sap1110 commented Oct 1, 2026 •

Copy link
Copy Markdown

If you gave the parser a weekday and a date that didn't match, it moved the date to fit the weekday. August 17 2026 is a Monday, so Wednesday August 17 2026 should give Aug 17, but it gave Wed Aug 19.

Now the date wins and the weekday is ignored, which is what GNU date does. Wednesday August 17 2026 gives Mon Aug 17.

This works for:

  • weekdays that match the date and weekdays that don't
  • named months, numeric and ISO dates, and forms with commas
  • inputs that include a time
  • next, last and ordinal weekdays. next Friday Sep 25 2026 now gives Sep 25, which also fixes the case in coreutils #14681.

These still work the same:

  • Relative items like +1 day or next week are applied after the date.
  • A weekday by itself (wed, wed 10:30) behaves as before.

The fix is one change in the builder: when a date is set, it clears the weekday. Because of that, the normal-year and large-year paths now behave the same.

I added a test with 22 cases, all checked against GNU date. 18 of them fail without the fix. One existing unit test expected the old behaviour, so I updated it to match what GNU gives.

Closes #317

@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 3.2%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 19 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ parse_invalid_input 59 µs 61 µs -3.28%
❌ parse_epoch_timestamp 14.8 µs 15.2 µs -3.12%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing sap1110:fix-weekday-with-explicit-date (b0c0424) with main (e25bf15)

Open in CodSpeed

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.32%. Comparing base (e25bf15) to head (b0c0424).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #335      +/-   ##
==========================================
- Coverage   97.48%   97.32%   -0.17%     
==========================================
  Files          21       21              
  Lines        4258     4261       +3     
  Branches      136      137       +1     
==========================================
- Hits         4151     4147       -4     
- Misses        106      113       +7     
  Partials        1        1              
Flag Coverage Δ
macos_latest 97.32% <100.00%> (-0.17%) ⬇️
ubuntu_latest 97.32% <100.00%> (-0.17%) ⬇️
windows_latest 12.20% <50.00%> (+0.03%) ⬆️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

When the input carries both a weekday and a calendar date, the date is
now authoritative and the weekday is dropped, matching GNU date. This
also covers ordinal forms such as "next friday sep 25 2026". Relative
items are still applied on top of the date, and a weekday without a
date behaves as before.

Closes uutils#317
@sap1110
sap1110 force-pushed the fix-weekday-with-explicit-date branch from 63edbf2 to b0c0424 Compare October 1, 2026 13:26
@sap1110

sap1110 commented Oct 1, 2026

Copy link
Copy Markdown
Author

Quick update: I looked at GNU's source before writing the first version, and I shouldn't have. I've thrown that version out and rewritten it from scratch. This time I only ran GNU date and checked what it does. The new version is force-pushed.

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.

date input: parser trusts weekday over explicit calendar date

1 participant