diff --git a/src/builtins/time.rs b/src/builtins/time.rs index a831e99..d1cb056 100644 --- a/src/builtins/time.rs +++ b/src/builtins/time.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Local}; +use chrono::{DateTime, Local, Utc}; use crate::error::ShellError; @@ -8,7 +8,7 @@ pub struct Time; impl Builtin for Time { fn execute(&mut self, _: &mut BuiltinConfig, args: Vec) -> Result<(), ShellError> { - let time = Local::now(); + let time = Utc::now(); let formatting = args.get(0).cloned().unwrap_or_default(); let time_string = format_time(time, &formatting); @@ -17,7 +17,7 @@ impl Builtin for Time { } } -fn format_time(time: DateTime, formatting: &str) -> String { +fn format_time(time: DateTime, formatting: &str) -> String { match formatting { "RFC2822" => time.to_rfc2822(), "RFC3339" => time.to_rfc3339(), @@ -27,6 +27,10 @@ fn format_time(time: DateTime, formatting: &str) -> String { #[cfg(test)] mod tests { + use std::str::FromStr; + + use chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeZone}; + use super::*; #[test]