Skip to content

Commit a4bd932

Browse files
committed
Update the time dev-dependency
1 parent ca65651 commit a4bd932

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

Cargo.lock

+47-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ openssl-probe = { version = "0.1", optional = true }
2828

2929
[dev-dependencies]
3030
clap = { version = "4.4.13", features = ["derive"] }
31-
time = "0.1.39"
31+
time = { version = "0.3.37", features = ["formatting"] }
3232
tempfile = "3.1.0"
3333

3434
[features]

examples/log.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,15 @@ fn print_commit(commit: &Commit) {
253253
}
254254

255255
fn print_time(time: &Time, prefix: &str) {
256-
let (offset, sign) = match time.offset_minutes() {
257-
n if n < 0 => (-n, '-'),
258-
n => (n, '+'),
259-
};
256+
let offset = time.offset_minutes();
260257
let (hours, minutes) = (offset / 60, offset % 60);
261-
let ts = time::Timespec::new(time.seconds() + (time.offset_minutes() as i64) * 60, 0);
262-
let time = time::at(ts);
258+
let dt = time::OffsetDateTime::from_unix_timestamp(time.seconds()).unwrap();
259+
let dto = dt.to_offset(time::UtcOffset::from_hms(hours as i8, minutes as i8, 0).unwrap());
260+
let format = time::format_description::parse("[weekday repr:short] [month repr:short] [day padding:space] [hour]:[minute]:[second] [year] [offset_hour sign:mandatory][offset_minute]")
261+
.unwrap();
262+
let time_str = dto.format(&format).unwrap();
263263

264-
println!(
265-
"{}{} {}{:02}{:02}",
266-
prefix,
267-
time.strftime("%a %b %e %T %Y").unwrap(),
268-
sign,
269-
hours,
270-
minutes
271-
);
264+
println!("{}{}", prefix, time_str);
272265
}
273266

274267
fn match_with_parent(

0 commit comments

Comments
 (0)