From 4d3e0341ffa627fee4d703ea86ffff60bd3a9c55 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 29 Dec 2024 12:34:22 +0800 Subject: [PATCH] feat: current-time.rs --- current-time-rs/src/main.rs | 13 +++++++++++-- script-meta.json | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/current-time-rs/src/main.rs b/current-time-rs/src/main.rs index 19fd81b..f541984 100755 --- a/current-time-rs/src/main.rs +++ b/current-time-rs/src/main.rs @@ -18,6 +18,9 @@ struct Args { /// Add time (e.g. 1s (second), 1m (minute), 1h (hour), 1d (day), 1M (month), 1y (year) ) #[arg(short, long)] add_time: Option, + /// Output format (e.g. millis (default), s|secs) + #[arg(short, long)] + output_format: Option, } fn main() { @@ -30,10 +33,16 @@ fn main() { let add_time_millis = parse_add_time(&args.add_time); let final_time_millis = current_time_millis as i128 + add_time_millis; + let output_format = args.output_format.map(|f| f.to_lowercase()); + let final_time = match output_format.as_deref() { + Some("s") | Some("secs") | Some("second") | Some("seconds") => final_time_millis / 1000, + _ => final_time_millis, + }; + if args.new_line { - println!("{}", final_time_millis); + println!("{}", final_time); } else { - print!("{}", final_time_millis); + print!("{}", final_time); } } diff --git a/script-meta.json b/script-meta.json index fbc18c1..b72dc6b 100644 --- a/script-meta.json +++ b/script-meta.json @@ -11,8 +11,8 @@ }, "current-time-rs": { "script_name": "current-time-rs", - "script_length": 1866, - "script_sha256": "f8980ea63a050398eceeae0b75983066b5e07dd348f46c08156462e526f9271c" + "script_length": 2226, + "script_sha256": "a8fd149fd0c64cc0c9d4b4deddf7b14d755249d2355670391521d0c7d108d538" }, "decrypt-rs": { "script_name": "decrypt-rs",