Skip to content

date: treat empty --file lines as midnight today like GNU - #14673

Open
Dummy-pixel-hash wants to merge 2 commits into
uutils:mainfrom
Dummy-pixel-hash:date-file-empty-midnight
Open

Dummy-pixel-hash wants to merge 2 commits into
uutils:mainfrom
Dummy-pixel-hash:date-file-empty-midnight

Conversation

@Dummy-pixel-hash

Copy link
Copy Markdown
Contributor

Fixes #14498.

Empty, whitespace-only, and lone - lines in --file/stdin input printed the current time; GNU treats them as midnight today. This normalizes such lines to midnight, mirroring the existing -d handling.

Empty, whitespace-only, and lone "-" lines in --file/stdin input
printed the current time instead of midnight. Normalize them to
midnight, mirroring the existing -d handling.

Fixes uutils#14498.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tty-eof (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/unexpand/bounded-memory is now passing!

Comment thread src/uu/date/src/date.rs
Ok(s) => parse_date(s, now, dbg_opts, allow_extended),
Ok(s) => {
let trimmed = s.trim();
if trimmed.is_empty() || trimmed == "-" {

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.

this duplicates the -d logic around line 493, could we share it?
the -d path also handles j and prints the --debug midnight warning, which we lose here

Comment thread src/uu/date/src/date.rs

/// Midnight at the start of `now`'s civil date, in its time zone.
///
/// Empty (whitespace-only or lone `-`) lines in `--file`/stdin input mean

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 repeats the one at the call site, please keep only the first line

fn test_date_file_empty_lines_are_midnight() {
// Empty, whitespace-only, and lone `-` lines mean midnight today,
// like GNU, not the current time (#14498).
let (at, mut ucmd) = at_and_ucmd!();

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.

could you please add a j line and a --debug case too?

}

#[test]
fn test_date_file_empty_lines_are_midnight() {

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.

did you check this with the GNU test suite?
bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/date/date.pl

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

2 participants