Repository navigation
date: treat blank lines in --file input as midnight today - #14523
TanbirRamim wants to merge 5 commits into
Conversation
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.
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 not alter performance1 warning
Comparing Footnotes
|
| 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"); |
There was a problem hiding this comment.
Done, thanks. I used show_error!("warning: ...") without the date: prefix, since the macro already prepends the util name; the output is unchanged.
6406bba to
5d3ed06
Compare
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.
Co-authored-by: Devel08 <[email protected]>
5d3ed06 to
5c994c7
Compare
# Conflicts: # src/uu/date/src/date.rs
| #[test] | ||
| fn test_date_file_blank_line_is_midnight_in_local_time() { |
|
Binary size comparison: |

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