feat: current-time.rs

This commit is contained in:
2024-12-29 12:34:22 +08:00
parent a3707f6d97
commit 4d3e0341ff
2 changed files with 13 additions and 4 deletions

View File

@@ -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<String>,
/// Output format (e.g. millis (default), s|secs)
#[arg(short, long)]
output_format: Option<String>,
}
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);
}
}

View File

@@ -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",