coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

date: implement --resolution

Open BenWiederhake opened this issue 10 months ago • 10 comments

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

BenWiederhake avatar Mar 29 '24 16:03 BenWiederhake

$ date --resolution
date: unrecognized option '--resolution'
Try 'date --help' for more information.

i tried this command in debian(wsl) but got this instead

biplab5464 avatar Apr 08 '24 17:04 biplab5464

@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?

tertsdiepraam avatar Apr 08 '24 18:04 tertsdiepraam

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

biplab5464 avatar Apr 19 '24 15:04 biplab5464

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.

BenWiederhake avatar Apr 20 '24 10:04 BenWiederhake

We can see what GNU does with strace though. There's probably a libc function for this somewhere.

tertsdiepraam avatar Apr 20 '24 11:04 tertsdiepraam

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

Dj-Codeman avatar Apr 23 '24 19:04 Dj-Codeman

@biplab5464, Just to clarify when you say "the resolution of the system." Are you reffering to cpu architecture, operating system or both ?

Dj-Codeman avatar Apr 23 '24 19:04 Dj-Codeman

@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.

tertsdiepraam avatar Apr 24 '24 08:04 tertsdiepraam

@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 avatar Apr 25 '24 15:04 biplab5464

@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.

Dj-Codeman avatar Apr 25 '24 23:04 Dj-Codeman