-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactoring ls and date #7194
Refactoring ls and date #7194
Conversation
GNU testsuite comparison:
|
@@ -0,0 +1,25 @@ | |||
mod timezone_date { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add the license header
/// Get the alphabetic abbreviation of the current timezone. | ||
/// | ||
/// For example, "UTC" or "CET" or "PDT". | ||
fn timezone_abbrev() -> &str { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please write unit test in this file :)
offset.abbreviation().unwrap_or("UTC").to_string() | ||
} | ||
|
||
/// Format the given time according to a custom format string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please document a bit more the arguments as rustdoc
Yes, that's the right place.
You have to wire it up in Hope that helps. |
Thanks for the feedbacks! |
GNU testsuite comparison:
|
src/uucore/Cargo.toml
Outdated
@@ -18,13 +18,16 @@ edition = "2021" | |||
path = "src/lib/lib.rs" | |||
|
|||
[dependencies] | |||
chrono = { workspace = true } | |||
chrono-tz = {workspace = true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A detail that should make the Style/toml
job in the CI pass:
chrono-tz = {workspace = true} | |
chrono-tz = { workspace = true } |
src/uu/ls/src/ls.rs
Outdated
@@ -386,7 +360,11 @@ impl TimeStyle { | |||
//So it's not yet implemented | |||
(Self::Locale, true) => time.format("%b %e %H:%M").to_string(), | |||
(Self::Locale, false) => time.format("%b %e %Y").to_string(), | |||
(Self::Format(e), _) => custom_time_format(e, time), | |||
(Self::Format(fmt), _) => { | |||
// this line can be replaced with the one in timzone_date.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this comment is no longer needed?
// this line can be replaced with the one in timzone_date.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right
src/uu/date/src/date.rs
Outdated
let format_string = &format_string | ||
.replace("%N", "%f") | ||
.replace("%Z", tz_abbreviation.unwrap_or("UTC")); | ||
let format_string = custom_time_format(&format_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy complains about this line:
let format_string = custom_time_format(&format_string); | |
let format_string = custom_time_format(format_string); |
GNU testsuite comparison:
|
Thanks! |
* refactoring ls and date * Refactored and integrated ls and date and added tests to the new feature * Style refactoring
This PR tries to refactor the common datetime formatting code in
ls
anddate
as requested in the issue #7156.I have created a new file under
uucore/lib/features
, but I am not sure if it is the right place. Moreover, I tried to import the module but without success, so I left theCargo.toml
of each crate as it was.Is it correct? How can I import the new module created?