Skip to content

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

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

date: treat blank lines in --file input as midnight today#14523
TanbirRamim wants to merge 2 commits into
uutils:mainfrom
TanbirRamim:date-blank-lines

Conversation

@TanbirRamim

Copy link
Copy Markdown

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

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

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

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/misc/io-errors (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/seq/seq-epipe is now passing!
Congrats! The gnu test tests/tail/pipe-f is now passing!
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

@codspeed-hq

codspeed-hq Bot commented Sep 12, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 3.94%

⚠️ 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

⚡ 1 improved benchmark
✅ 366 untouched benchmarks
⏩ 50 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_all_wide_tree[(5000, 500)] 38.6 ms 37.1 ms +3.94%

Tip

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


Comparing TanbirRamim:date-blank-lines (a525e7b) with main (4bae306)2

Open in CodSpeed

Footnotes

  1. 50 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.

  2. No successful run was found on main (92076ab) during the generation of this report, so 4bae306 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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
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");

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