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