Skip to content

Commit

Permalink
timeapp.rs : fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
trou committed Dec 18, 2023
1 parent 0f8451f commit 43b1971
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/timeapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ impl Applet for TimeApplet {
}

fn new() -> Box<dyn Applet> {
Box::new(Self { local: false, verbose: false })
Box::new(Self {
local: false,
verbose: false,
})
}

fn parse_args(&self, args: &clap::ArgMatches) -> Result<Box<dyn Applet>> {
Expand All @@ -96,28 +99,37 @@ impl Applet for TimeApplet {
(12, _) =>
/* Epoch centiseconds */
{
(decode_epoch_subseconds(ts_int, 100), "Centiseconds since Epoch")
(
decode_epoch_subseconds(ts_int, 100),
"Centiseconds since Epoch",
)
}
(13, _) =>
/* Epoch milliseconds */
{
(decode_epoch_subseconds(ts_int, 1000), "Milliseconds since Epoch")
(
decode_epoch_subseconds(ts_int, 1000),
"Milliseconds since Epoch",
)
}
(16, _) =>
/* Epoch microseconds */
{
(decode_epoch_subseconds(ts_int, 1_000_000), "Microseconds since Epoch")
(
decode_epoch_subseconds(ts_int, 1_000_000),
"Microseconds since Epoch",
)
}
(18, _) =>
/* Windows FILETIME */
{
(decode_windows_filetime(ts_int), "Windows FILETIME")
}
_ => (decode_epoch_seconds(ts_int), "Seconds since Epoch")
_ => (decode_epoch_seconds(ts_int), "Seconds since Epoch"),
};
let tse = ts.with_context(|| "Could not convert timestamp")?;
if self.verbose {
eprintln!("Used format: {}", type_str);
eprintln!("Used format: {}", type_str);
}
let ts = if self.local {
let offset = UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC);
Expand All @@ -142,7 +154,10 @@ mod tests {

#[test]
fn test_decimal() {
let ts = TimeApplet { local: false, verbose: false };
let ts = TimeApplet {
local: false,
verbose: false,
};
assert_eq!(run_decode(&ts, "0"), "1970-01-01T00:00:00Z");
assert_eq!(run_decode(&ts, "1420070400"), "2015-01-01T00:00:00Z");
assert_eq!(run_decode(&ts, "142007040000"), "2015-01-01T00:00:00Z");
Expand All @@ -166,7 +181,10 @@ mod tests {

#[test]
fn test_hex() {
let ts = TimeApplet { local: false, verbose: false };
let ts = TimeApplet {
local: false,
verbose: false,
};
assert_eq!(run_decode(&ts, "0x0"), "1970-01-01T00:00:00Z");
assert_eq!(run_decode(&ts, "0x1"), "1970-01-01T00:00:01Z");
}
Expand Down

0 comments on commit 43b1971

Please # to comment.