Browse Source

feat: change time from local to utc

main
fdai7375 2 years ago
committed by fdai7451
parent
commit
6715ffb74f
  1. 10
      src/builtins/time.rs

10
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<String>) -> 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<Local>, formatting: &str) -> String {
fn format_time(time: DateTime<Utc>, formatting: &str) -> String {
match formatting {
"RFC2822" => time.to_rfc2822(),
"RFC3339" => time.to_rfc3339(),
@ -27,6 +27,10 @@ fn format_time(time: DateTime<Local>, formatting: &str) -> String {
#[cfg(test)]
mod tests {
use std::str::FromStr;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeZone};
use super::*;
#[test]

Loading…
Cancel
Save