coreutils
coreutils copied to clipboard
date: implement --resolution
This sounds like a feature that people probably use:
$ date --resolution
0.000000001
$ cargo run date --resolution
error: unexpected argument '--resolution' found
tip: a similar argument exists: '--version'
Usage: target/debug/coreutils date [OPTION]... [+FORMAT]...
target/debug/coreutils date [OPTION]... [MMDDhhmm[[CC]YY][.ss]]
For more information, try '--help'.
[$? = 1]
When you implement it, please make sure that you set overrides_with
, so that date --resolution --resolution
also works :)
Found while working on #6142
$ date --resolution
date: unrecognized option '--resolution'
Try 'date --help' for more information.
i tried this command in debian(wsl) but got this instead
@biplab5464 Strange, because it is documented: https://www.gnu.org/software/coreutils/manual/html_node/Options-for-date.html
It was introduced in GNU coreutils 9.1. Maybe you have an older version?
Hi, I tried to implement date --resolution but i am unable to find how to implement the logic for getting the resolution of the system. I went thought internet also the gnu coreutils but didn't got a constructive idea how to implement this logic.
do you have some reference which can help me
Thanks
Stealing tert's summary of the sourcecode situation:
Please don't look at or link the GNU source code. That policy is our guarantee that uutils is original code. The documentation fair game though.
That said, if I knew how to get the resolution reliably and correctly, I probably would have already implemented it ^^'
I was hoping that it's in std::fs
or somewhere related.
Thank you for investing the time, then I guess it's not easy, and shouldn't be marked as "good first issue", my bad.
We can see what GNU does with strace though. There's probably a libc function for this somewhere.
Hi, I'm taking a pass at this , I have the logic for --resolution
but I can't figure out parsing to pass the flag to date. Any Info would be appreciated ! So far I've got this by println!("{}", TimeResolution::new());
in uumain
cargo run date
...
Running `target/debug/coreutils date`
0.000000001
Tue Apr 23 14:11:01 2024
@biplab5464, Just to clarify when you say "the resolution of the system." Are you reffering to cpu architecture, operating system or both ?
@Dj-Codeman Nice! The argument parsing is done with clap. You can look at the other flags to see how it's done. To answer your other question: whatever matches GNU! I guess that's the OS time resolution.
@Dj-Codeman i learned that resolution is the lowest time measurable by the system. can you tell me where is the doc for TimeResolution::new() in rust. maybe i can help with argument passing.
@biplab5464 Sorry my comment was written poorly. I'm adding this: TimeResolution::new()
. I just open a draft PR: #6272. I wasn't sure If that was the correct thing to do since I hadn't finished it yet.