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

Is there a way to get the TimeDelta in an human-friendly way like "10h26m"? #1616

Open
frederikhors opened this issue Sep 21, 2024 · 3 comments

Comments

@frederikhors
Copy link
Contributor

I opened an old project that was using time crate.

I have this code:

let diff = end_date - start_date;

let result = diff.to_string();

and result there is "10h26m".

Now with chrono crate I get something like: "PT15240S".

Is there a way to get the result like with the time crate, in a more human friendly way?

@djc
Copy link
Member

djc commented Sep 21, 2024

There isn't, currently. The humantime crate exists and I think might do this?

@frederikhors
Copy link
Contributor Author

I "fixed" with a custom function. Shoud we leave this open?

@djc
Copy link
Member

djc commented Sep 21, 2024

Probably fine to keep this open, might be useful at some point.

There is what I believe to be a reasonable implementation here that we could copy/adapt:

https://github.com/console-rs/indicatif/blob/main/src/format.rs#L74

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

No branches or pull requests

2 participants