Skip to content

Conversation

@Banzobotic
Copy link
Contributor

@Banzobotic Banzobotic commented Sep 20, 2025

Implements the --resolution flag for date. On unix platforms this uses the posix function clock_getres. I could not find an equivalent syscall on windows, however every windows operating system since at least Windows 2000 has used a resolution of 100ns, so I decided to hardcode that as the returned resolution.

I treated the --resolution flag as a date source like it is in GNU date, this allows other formatting flags to apply to the output of the --resolution flag. I also tried to make sure the implementation would interact well with a future implementation of the --debug flag.

As a bit of a drive by I also add conflicts_with annotations to the four date source options, this is to make the GNU date behaviour of failing when multiple date sources are specified. However, I'm not sure if I've taken the best approach for this, since the error message is different to GNU make and I'm not sure whether or not this is an issue.

date -d "2025-01-01" --resolution

gnu date:
date: the options to specify dates for printing are mutually exclusive
Try 'date --help' for more information.

this pr:
error: the argument '--date <STRING>' cannot be used with '--resolution'

For more information, try '--help'.

fixes #6143

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 21, 2025

CodSpeed Performance Report

Merging #8686 will create unknown performance changes

Comparing Banzobotic:add_date_resolution (5e0d9cd) with main (837bc48)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.\

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@Banzobotic
Copy link
Contributor Author

Banzobotic commented Sep 21, 2025

I'm not sure how best to solve the redox os issue. Redox doesn't support the clock_getres function. Looking at the source code, the precision for reading the time is hardware dependent, however the precision of the underlying primitive is 1ns. So, I could just do what I do for windows and return a resolution of 1ns, and add a todo to switch to using clock_getres once redox os supports it. Is this fine?

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@cakebaker cakebaker merged commit 542e476 into uutils:main Sep 22, 2025
98 checks passed
@cakebaker
Copy link
Contributor

Thanks for your PR!

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: implement --resolution

2 participants