Skip to content

stat: add support for nanosecond format directives - #14757

Open
krosci wants to merge 1 commit into
uutils:mainfrom
krosci:fix/stat-nanosecond-formats
Open

krosci wants to merge 1 commit into
uutils:mainfrom
krosci:fix/stat-nanosecond-formats

Conversation

@krosci

@krosci krosci commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

This change resolves stat-nanoseconds.sh from the GNU 9.12 test suite tracked in #14705 by implementing the nanosecond format directives %:X, %:Y, %:Z, and %:W. These specifiers format the timestamp nanosecond component as a 9-digit zero-padded string while honoring width and alignment flags. Automated tests have been added to verify output formatting and error handling.

Comment thread src/uu/stat/src/stat.rs Outdated
'x' => OutputType::Str(pretty_time(meta, MetadataTimeField::Access)),
// time of last access, seconds since Epoch
'X' if flag.nanoseconds => {
let (_, nsec) = metadata_get_time(meta, MetadataTimeField::Access)

@sylvestre sylvestre Sep 20, 2026

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 be dedup, no ?
almost the same code 3 times

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.

Right, I'm done.

@krosci
krosci force-pushed the fix/stat-nanosecond-formats branch from 7d2fd23 to 9f87ed6 Compare September 20, 2026 15:19
Comment thread src/uu/stat/src/stat.rs Outdated

const PRETTY_DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S.%N %z";

fn time_field(format: char) -> MetadataTimeField {

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.

seems like a too generic function name here

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.

What should I name it?

@github-actions

github-actions Bot commented Sep 20, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/df/skip-rootfs. tests/df/skip-rootfs is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/id/smack. tests/id/smack is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/mkdir/smack-root. tests/mkdir/smack-root is passing on 'main'. Maybe you have to rebase?

@krosci
krosci force-pushed the fix/stat-nanosecond-formats branch from 9f87ed6 to d833607 Compare September 21, 2026 12:51
@krosci
krosci force-pushed the fix/stat-nanosecond-formats branch from d833607 to ca29240 Compare September 21, 2026 16:09
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.

2 participants