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 behaves differently with no args #3756

Open
rayan-mazouz opened this issue Jul 29, 2022 · 13 comments
Open

date behaves differently with no args #3756

rayan-mazouz opened this issue Jul 29, 2022 · 13 comments
Labels

Comments

@rayan-mazouz
Copy link

rayan-mazouz commented Jul 29, 2022

date behaves differently than coreutils when no argument is passed, if the goal of the project is to behave a 100% like the gnu coreutils, this should be fixed. here are two examples , it should be pretty easy to reproduce unless it's a weird problem with both my systems (manjaro and endeavour os)


Exemple 1 :

image
$./date
Fri Jul 29 09:09:10 2022
$date
$Fri 29 Jul 2022 09:09:12 CEST


Exemple 2 :

image
$./date
Fri Jul 29 16:40:39 2022
$date
$Fri Jul 29 04:40:40 PM CDT 2022


I looked at the code and i think it's caused by the chrono dependency not correctly detecting the current locale when formatting with %c. not sure about that though.

@sylvestre
Copy link
Sponsor Contributor

Could you please replace the screen shot by some text?
Screenshots for code are terrible foe accessibility and search

Thanks

@sylvestre sylvestre added the good first issue For newcomers! label Jul 29, 2022
@rayan-mazouz
Copy link
Author

done.

I think this is related to this issue
chronotope/chrono#708

@Stonks3141
Copy link
Contributor

I’ll work on this one. Would it be okay for this project to use chrono’s unstable-locales feature?

@s1gse9v
Copy link

s1gse9v commented Jul 30, 2022

I'm pretty sure this can be fixed by just changing Format::Default => "%c" to Format::Default => "%a %b %d %I:%M:%S %Z %p %Y" in line 351. However, as of now, %Z does not behave as expected. I already opened an issue chronotope/chrono#749

@Stonks3141
Copy link
Contributor

Stonks3141 commented Jul 31, 2022

I don't think it does, this is from after changing to "%a %b %d %I:%M:%S %Z %p %Y":

$ LC_ALL=fr_FR.UTF-8 cargo run date
Sat Jul 30 20:38:57 2022
$ LC_ALL=fr_FR.UTF-8 date
sam. 30 juil. 2022 20:39:25 EDT

@Stonks3141
Copy link
Contributor

Stonks3141 commented Jul 31, 2022

chrono's format_localized isn't the same as GNU either though:

$ LC_ALL=en_US.UTF-8 cargo run date
Sat 30 Jul 2022 08:48:56 PM -04:00

$ LC_ALL=en_US.UTF-8 date
Sat Jul 30 08:49:01 PM EDT 2022

It's mostly the same, but pure-rust-locales, which chrono uses for unstable-locales, differs from GNU date for some locales.

@rayan-mazouz
Copy link
Author

can we directly call libc ? I have a fix if unsafe code is allowed but obviously it's not ideal

@tertsdiepraam
Copy link
Member

@rayan-mazouz libc is fine, we call it all throughout the codebase. But if there is a wrapper function in nix or some cross-platform solution, that would be preferable.

@rayan-mazouz
Copy link
Author

@tertsdiepraam great thanks, my fix works for linux, I'll try to make it work on mac, windows and redox, then do a merge request

@tertsdiepraam
Copy link
Member

I wonder if we can start using icu4x for this. Specifically the icu_datetime component. Though, it might not be flexible enough yet.

@Ecordonnier
Copy link
Contributor

@rayan-mazouz is your fix for linux available on some branch? I'd like to investigate this issue.

@rayan-mazouz
Copy link
Author

sorry, it is not.

@KrishnaNagam
Copy link

KrishnaNagam commented Aug 15, 2023

There seems to be a workaround to get locale.
chronotope/chrono#960 (comment)

I have raised a PR with the above fix: #5164

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

Successfully merging a pull request may close this issue.

8 participants