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

Remove time dependency from date #4952

Merged
merged 4 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fundu = "0.5.1"
gcd = "2.3"
glob = "0.3.1"
half = "2.2"
humantime_to_duration = "0.2.1"
humantime_to_duration = "0.3.1"
indicatif = "0.17"
is-terminal = "0.4.7"
itertools = "0.10.5"
Expand Down
2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ skip = [
{ name = "redox_syscall", version = "0.3.5" },
# cpp_macros
{ name = "aho-corasick", version = "0.7.19" },
# touch, can be remove when touch switches from time to chrono
{ name = "humantime_to_duration", version = "0.2.1" },
]
# spell-checker: enable

Expand Down
2 changes: 0 additions & 2 deletions src/uu/date/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ path = "src/date.rs"

[dependencies]
chrono = { workspace=true }
#/ TODO: check if we can avoid chrono+time
time = { workspace=true }
clap = { workspace=true }
uucore = { workspace=true }
humantime_to_duration = { workspace=true }
Expand Down
12 changes: 4 additions & 8 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes humantime

use chrono::format::{Item, StrftimeItems};
use chrono::{DateTime, Duration as ChronoDuration, FixedOffset, Local, Offset, Utc};
use chrono::{DateTime, Duration, FixedOffset, Local, Offset, Utc};
#[cfg(windows)]
use chrono::{Datelike, Timelike};
use clap::{crate_version, Arg, ArgAction, Command};
Expand All @@ -18,7 +18,6 @@ use libc::{clock_settime, timespec, CLOCK_REALTIME};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use time::Duration;
use uucore::display::Quotable;
#[cfg(not(any(target_os = "redox")))]
use uucore::error::FromIo;
Expand Down Expand Up @@ -226,13 +225,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let iter = std::iter::once(date);
Box::new(iter)
}
DateSource::Human(ref input) => {
// Get the current DateTime<FixedOffset> and convert the input time::Duration to chrono::Duration
// for things like "1 year ago"
DateSource::Human(relative_time) => {
// Get the current DateTime<FixedOffset> for things like "1 year ago"
let current_time = DateTime::<FixedOffset>::from(Local::now());
let input_chrono = ChronoDuration::seconds(input.as_seconds_f32() as i64)
+ ChronoDuration::nanoseconds(input.subsec_nanoseconds() as i64);
let iter = std::iter::once(Ok(current_time + input_chrono));
let iter = std::iter::once(Ok(current_time + relative_time));
Box::new(iter)
}
DateSource::File(ref path) => {
Expand Down
3 changes: 2 additions & 1 deletion src/uu/touch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ path = "src/touch.rs"
[dependencies]
filetime = { workspace=true }
clap = { workspace=true }
humantime_to_duration = { workspace=true }
# TODO: use workspace dependency (0.3) when switching from time to chrono
humantime_to_duration = "0.2.1"
time = { workspace=true, features = ["parsing", "formatting", "local-offset", "macros"] }
uucore = { workspace=true, features=["libc"] }

Expand Down