镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Merged
sylvestre merged 2 commits into
uutils:mainfrom
sap1110:fix-weekday-with-explicit-date
Oct 5, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
sap1110:fix-weekday-with-explicit-date

Conversation

@sap1110

@sap1110 sap1110 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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 improve performance by 3.2%

⚡ 1 improved benchmark
✅ 20 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ parse_ctime_format 71.2 µs 69 µs +3.2%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing sap1110:fix-weekday-with-explicit-date (7ab830e) with main (ed95575)

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.58%. Comparing base (e25bf15) to head (7ab830e).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #335      +/-   ##
==========================================
+ Coverage   97.48%   97.58%   +0.09%     
==========================================
  Files          21       21              
  Lines        4258     4389     +131     
  Branches      136      138       +2     
==========================================
+ Hits         4151     4283     +132     
+ Misses        106      105       -1     
  Partials        1        1              
Flag Coverage Δ
macos_latest 97.58% <100.00%> (+0.09%) ⬆️
ubuntu_latest 97.58% <100.00%> (+0.09%) ⬆️
windows_latest 12.41% <50.00%> (+0.25%) ⬆️

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
Contributor 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.

Comment thread src/items/builder.rs Outdated
/// - e. Apply relative adjustments (e.g., "+3 days", "-2 months").
pub(super) fn build(self) -> Result<ParsedDateTime, error::Error> {
pub(super) fn build(mut self) -> Result<ParsedDateTime, error::Error> {
// An explicit calendar date wins over a weekday, even a mismatching

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the doc comment just above already says this, could we drop this one or keep it to one line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, removed it. The doc comment already covers the weekday case and the if is clear enough without it.

Comment thread tests/date.rs Outdated
// $ TZ=UTC date -d 'wed 10:30' # next wednesday at 10:30
//
// `date --debug` warns that the day is ignored when explicit dates are
// given. Verified against GNU coreutils 9.7, with the base below being

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the PR description says GNU 8.32, here 9.7, which one is it?
and the latest is 9.12

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I re-ran all 22 cases against 9.12 and they match 9.7 exactly. The test comment now only mentions 9.12. The 8.32 was in the old PR description, which I've since replaced. No distro packages 9.12 yet, so I built it from the GNU release tarball.

Comment thread tests/date.rs Outdated
);
}

// A weekday is ignored when an explicit calendar date is given, whether or

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please make the comment shorter, the case names already explain most of it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, it's two lines now. It just notes that the weekday is ignored when an explicit date is given, matching GNU date 9.12.

@sylvestre
sylvestre merged commit 5bc4b0a into uutils:main Oct 5, 2026
21 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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

2 participants