From 6715ffb74f93e58726c3aac968032ebe3c48ba62 Mon Sep 17 00:00:00 2001 From: fdai7375 Date: Thu, 2 Feb 2023 20:50:56 +0100 Subject: [PATCH] feat: change time from local to utc --- src/builtins/time.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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]