Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date: implement --resolution #6143

Open
BenWiederhake opened this issue Mar 29, 2024 · 10 comments
Open

date: implement --resolution #6143

BenWiederhake opened this issue Mar 29, 2024 · 10 comments
Labels

Comments

@BenWiederhake
Copy link
Collaborator

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

@biplab5464
Copy link
Contributor

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

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

@tertsdiepraam
Copy link
Member

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

@biplab5464
Copy link
Contributor

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

@BenWiederhake BenWiederhake removed the good first issue For newcomers! label Apr 20, 2024
@BenWiederhake
Copy link
Collaborator Author

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.

@tertsdiepraam
Copy link
Member

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

@Dj-Codeman
Copy link

Dj-Codeman commented Apr 23, 2024

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
Copy link

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

@tertsdiepraam
Copy link
Member

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

@biplab5464
Copy link
Contributor

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

@Dj-Codeman
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants