Skip to content

Commit

Permalink
Update the time dev-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jan 5, 2025
1 parent ca65651 commit a4bd932
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
59 changes: 47 additions & 12 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 @@ -28,7 +28,7 @@ openssl-probe = { version = "0.1", optional = true }

[dev-dependencies]
clap = { version = "4.4.13", features = ["derive"] }
time = "0.1.39"
time = { version = "0.3.37", features = ["formatting"] }
tempfile = "3.1.0"

[features]
Expand Down
21 changes: 7 additions & 14 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,15 @@ fn print_commit(commit: &Commit) {
}

fn print_time(time: &Time, prefix: &str) {
let (offset, sign) = match time.offset_minutes() {
n if n < 0 => (-n, '-'),
n => (n, '+'),
};
let offset = time.offset_minutes();
let (hours, minutes) = (offset / 60, offset % 60);
let ts = time::Timespec::new(time.seconds() + (time.offset_minutes() as i64) * 60, 0);
let time = time::at(ts);
let dt = time::OffsetDateTime::from_unix_timestamp(time.seconds()).unwrap();
let dto = dt.to_offset(time::UtcOffset::from_hms(hours as i8, minutes as i8, 0).unwrap());
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]")
.unwrap();
let time_str = dto.format(&format).unwrap();

println!(
"{}{} {}{:02}{:02}",
prefix,
time.strftime("%a %b %e %T %Y").unwrap(),
sign,
hours,
minutes
);
println!("{}{}", prefix, time_str);
}

fn match_with_parent(
Expand Down

0 comments on commit a4bd932

Please sign in to comment.