date: treat blank lines in --file input as midnight today - #14523
date: treat blank lines in --file input as midnight today#14523TanbirRamim wants to merge 2 commits into
Conversation
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
There was a problem hiding this comment.
🔵 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 make00:00resolve to 23:00 of the previous day, so a blank--fileline is not midnight. Compute the offset for the date's start of day (or construct that localZoned) 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.
There was a problem hiding this comment.
🟢 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
|
GNU testsuite comparison: |
Merging this PR will improve performance by 3.94%
|
| 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
Footnotes
-
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. ↩
-
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. ↩
| 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; |
There was a problem hiding this comment.
we can use the show_error macro instead of writing to stderr
| use uucore::show_error; | |
| use uucore::translate; |
| let _ = writeln!( | ||
| stderr(), | ||
| "date: warning: using midnight as starting time: 00:00:00" | ||
| ); |
There was a problem hiding this comment.
| 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"); |
date --fileprinted the current time for an empty line, while GNU prints midnight today, the same asdate -d ''. GNU treats a whitespace-only line and a lone-the same way.The midnight composition is now shared between the
-dpath and the file reader, and blank lines and-go through it, honoring-ulike-d ''does.Fixes #14498