|
@ -1,4 +1,4 @@ |
|
|
use chrono::Local;
|
|
|
|
|
|
|
|
|
use chrono::{DateTime, Local};
|
|
|
|
|
|
|
|
|
use crate::error::ShellError;
|
|
|
use crate::error::ShellError;
|
|
|
|
|
|
|
|
@ -10,17 +10,17 @@ impl Builtin for Time { |
|
|
fn execute(&mut self, _: &mut BuiltinConfig, args: Vec<String>) -> Result<(), ShellError> {
|
|
|
fn execute(&mut self, _: &mut BuiltinConfig, args: Vec<String>) -> Result<(), ShellError> {
|
|
|
let time = Local::now();
|
|
|
let time = Local::now();
|
|
|
|
|
|
|
|
|
if args.is_empty() {
|
|
|
|
|
|
println!("{}", time.format("%T"));
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
|
|
|
let formatting = args.get(0).cloned().unwrap_or_default();
|
|
|
|
|
|
let time_string = format_time(time, &formatting);
|
|
|
|
|
|
println!("{time_string}");
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
let time_string = match args[0].as_str() {
|
|
|
|
|
|
|
|
|
fn format_time(time: DateTime<Local>, formatting: &str) -> String {
|
|
|
|
|
|
match formatting {
|
|
|
"RFC2822" => time.to_rfc2822(),
|
|
|
"RFC2822" => time.to_rfc2822(),
|
|
|
"RFC3339" => time.to_rfc3339(),
|
|
|
"RFC3339" => time.to_rfc3339(),
|
|
|
_ => time.format("%T").to_string(),
|
|
|
_ => time.format("%T").to_string(),
|
|
|
};
|
|
|
|
|
|
println!("{time_string}");
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|