Skip to content

Commit 04a50aa

Browse files
cakebakersylvestre
authored andcommitted
vmstat,w: adapt to API change in jiff
1 parent bfa007c commit 04a50aa

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎src/uu/vmstat/src/picker.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ pub fn get_pickers(matches: &ArgMatches) -> Vec<Picker> {
6969
pickers.push(concat_helper(
7070
(
7171
"-----timestamp-----".into(),
72-
format!("{:>19}", jiff::Zoned::now().strftime("%Z").to_string()),
72+
format!(
73+
"{:>19}",
74+
jiff::ZonedDateTime::now().strftime("%Z").to_string()
75+
),
7376
),
7477
get_timestamp,
7578
));
@@ -522,6 +525,8 @@ fn get_timestamp(
522525
) -> Vec<(usize, String)> {
523526
vec![(
524527
10,
525-
jiff::Zoned::now().strftime("%Y-%m-%d %H:%M:%S").to_string(),
528+
jiff::ZonedDateTime::now()
529+
.strftime("%Y-%m-%d %H:%M:%S")
530+
.to_string(),
526531
)]
527532
}

‎src/uu/w/src/w.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use clap::crate_version;
77
use clap::{Arg, ArgAction, Command};
88
#[cfg(target_os = "linux")]
9-
use jiff::Zoned;
9+
use jiff::ZonedDateTime;
1010
#[cfg(target_os = "linux")]
1111
use std::{collections::HashMap, fs, path::Path, time::SystemTime};
1212
use std::{process, time::Duration};
@@ -128,8 +128,8 @@ fn format_time(time: String) -> Result<String, jiff::Error> {
128128
t = t.drain(..time_offset).collect();
129129
}
130130
// If login time day is not current day, format like Sat16, or Fri06
131-
let current_dt = Zoned::now();
132-
let dt = Zoned::strptime("%Y-%m-%d %H:%M:%S%.f %:z", &t)?;
131+
let current_dt = ZonedDateTime::now();
132+
let dt = ZonedDateTime::strptime("%Y-%m-%d %H:%M:%S%.f %:z", &t)?;
133133
if current_dt.day() == dt.day() {
134134
Ok(dt.strftime("%H:%M").to_string())
135135
} else {
@@ -412,18 +412,18 @@ mod tests {
412412
fetch_cmdline, fetch_pcpu_time, fetch_terminal_number, format_time, format_time_elapsed,
413413
format_uptime_procps, get_clock_tick,
414414
};
415-
use jiff::{SignedDuration, Zoned};
415+
use jiff::{SignedDuration, ZonedDateTime};
416416
use std::{fs, path::Path, process, time::Duration};
417417

418418
#[test]
419419
fn test_format_time() {
420-
let unix_epoc = Zoned::now()
420+
let unix_epoc = ZonedDateTime::now()
421421
.strftime("%Y-%m-%d %H:%M:%S%.6f %::z")
422422
.to_string();
423423
let unix_formatted = format_time(unix_epoc).unwrap();
424424
assert!(unix_formatted.contains(':') && unix_formatted.chars().count() == 5);
425425
// Test a date that is 5 days ago
426-
let td = Zoned::now() - SignedDuration::from_secs(60 * 60 * 24 * 5);
426+
let td = ZonedDateTime::now() - SignedDuration::from_secs(60 * 60 * 24 * 5);
427427
// Pre-format time, so it's similar to how utmpx returns it
428428
let pre_formatted = format!("{}", td.strftime("%Y-%m-%d %H:%M:%S%.6f %::z"));
429429

0 commit comments

Comments
 (0)