Skip to content

date: treat blank lines in --file input as midnight today - #14523

Open
TanbirRamim wants to merge 5 commits into
uutils:mainfrom
TanbirRamim:date-blank-lines
Open

TanbirRamim wants to merge 5 commits into
uutils:mainfrom
TanbirRamim:date-blank-lines

Conversation

@TanbirRamim

Copy link
Copy Markdown
Contributor

date --file printed the current time for an empty line, while GNU prints midnight today, the same as date -d ''. GNU treats a whitespace-only line and a lone - the same way.

The midnight composition is now shared between the -d path and the file reader, and blank lines and - go through it, honoring -u like -d '' does.

Fixes #14498

Copilot AI lite review requested due to automatic review settings September 12, 2026 20:53

Copilot AI left a comment

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.

🔵 Needs a closer look

The current offset may produce the wrong local midnight on DST transition days.

Pull request overview

Updates date --file so blank, whitespace-only, and - inputs resolve to midnight today like date -d '', including UTC handling.

Changes:

  • Shares midnight composition between date input paths.
  • Adds regression coverage for blank, CRLF, whitespace, -, and timezone behavior.
File summaries
File Description
tests/by-util/test_date.rs Adds regression tests for blank-line and timezone behavior.
src/uu/date/src/date.rs Implements shared midnight handling. A moderate finding remains regarding DST offset calculation at local midnight.
Review details

Suppressed comments (1)

src/uu/date/src/date.rs:1155

  • strtime::format("%:z", now) is the offset at the current instant, not necessarily the offset at local midnight. On a DST transition day, composing today's date with the current offset can make 00:00 resolve to 23:00 of the previous day, so a blank --file line is not midnight. Compute the offset for the date's start of day (or construct that local Zoned) before parsing.
    let offset = if utc {
        String::from("+00:00")
    } else {
        strtime::format("%:z", now).unwrap_or_default()
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 12, 2026 21:19

Copilot AI left a comment

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.

🟢 Approval recommended

Only minor reproducibility nits remain; no blocking issues were identified.

Review details

Suppressed comments (3)

Previously missed (2) — in code that hasn't changed since the last review.

src/uu/date/src/date.rs:1183

  • Please name the recent GNU version used to verify this compatibility claim; an unversioned “GNU compatibility” assertion is not reproducible.
    tests/by-util/test_date.rs:688
  • Please include the exact recent GNU version used to verify this test expectation; compatibility claims should be reproducible rather than referring to an unspecified GNU behavior.

src/uu/date/src/date.rs:1148

  • Please name the recent GNU version used to verify this compatibility claim (or remove the GNU attribution); new GNU-behavior claims need a version so the result is reproducible.
/// GNU parses an empty date string (or a lone `-`) as midnight today; this is
/// the equivalent input for our parser. The start of the day is resolved in
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/id/setgid is no longer failing!

@codspeed

codspeed Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 12 untouched benchmarks
⏩ 460 skipped benchmarks1


Comparing TanbirRamim:date-blank-lines (efde624) with main (bac5160)

Open in CodSpeed

Footnotes

  1. 460 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread src/uu/date/src/date.rs
use uucore::error::{UError, UResult, USimpleError, strip_errno};
#[cfg(feature = "i18n-datetime")]
use uucore::i18n::datetime::{localize_format_string, should_use_icu_locale};
use uucore::translate;

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.

we can use the show_error macro instead of writing to stderr

Suggested change
use uucore::show_error;
use uucore::translate;

Comment thread src/uu/date/src/date.rs Outdated
Comment on lines +1186 to +1189
let _ = writeln!(
stderr(),
"date: warning: using midnight as starting time: 00:00:00"
);

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.

Suggested change
let _ = writeln!(
stderr(),
"date: warning: using midnight as starting time: 00:00:00"
);
show_error!("date: warning: using midnight as starting time: 00:00:00");

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, thanks. I used show_error!("warning: ...") without the date: prefix, since the macro already prepends the util name; the output is unchanged.

Copilot AI review requested due to automatic review settings September 19, 2026 18:26

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 23, 2026 13:39

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

TanbirRamim and others added 3 commits September 29, 2026 22:43
GNU date parses an empty line (or a lone "-") from --file the same way it
parses `-d ''`: as midnight today. We only did that for -d, and printed
the current time for such lines instead.

Share the midnight composition between the two paths and use it for
blank lines and "-" in the file reader as well.

Fixes uutils#14498
Composing today's date with the offset of the current instant gives the
wrong midnight on a DST transition day, where the offset at 00:00 differs
from the offset now. Take the start of the day from the zoned time instead
and format that, so the composed string carries midnight's own offset.
Copilot AI lite review requested due to automatic review settings September 29, 2026 20:44

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI lite review requested due to automatic review settings October 4, 2026 19:18

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

Only a non-blocking documentation nit remains; the implementation and tests are otherwise ready.

Review effort: Lite
Findings: None

Copilot AI lite review requested due to automatic review settings October 23, 2026 03:03

Copilot AI left a comment

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.

🟡 Changes recommended

The timezone-dependent test needs a WASI guard before approval.

1 open issue

Review effort: Lite

Comment on lines +915 to +916
#[test]
fn test_date_file_blank_line_is_midnight_in_local_time() {
@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.04 MB (-304 KB, -0.19%)

Significant per-binary changes:
  date     2.61 MB ->    2.31 MB  (-312 KB, -11.66%)

This branch has not been deployed

No deployments
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: --file flag outputs different date on EOF of empty file in stdin mode

3 participants