|
@ -1,4 +1,4 @@ |
|
|
use chrono::{DateTime, Local};
|
|
|
|
|
|
|
|
|
use chrono::{DateTime, Local, Utc};
|
|
|
|
|
|
|
|
|
use crate::error::ShellError;
|
|
|
use crate::error::ShellError;
|
|
|
|
|
|
|
|
@ -8,7 +8,7 @@ pub struct Time; |
|
|
|
|
|
|
|
|
impl Builtin for Time {
|
|
|
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 = Utc::now();
|
|
|
|
|
|
|
|
|
let formatting = args.get(0).cloned().unwrap_or_default();
|
|
|
let formatting = args.get(0).cloned().unwrap_or_default();
|
|
|
let time_string = format_time(time, &formatting);
|
|
|
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 {
|
|
|
match formatting {
|
|
|
"RFC2822" => time.to_rfc2822(),
|
|
|
"RFC2822" => time.to_rfc2822(),
|
|
|
"RFC3339" => time.to_rfc3339(),
|
|
|
"RFC3339" => time.to_rfc3339(),
|
|
@ -27,6 +27,10 @@ fn format_time(time: DateTime<Local>, formatting: &str) -> String { |
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
mod tests {
|
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
|
|
|
|
use chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeZone};
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|