From 6b8cf6d167c41a30364d1a528e5bc335111a3c74 Mon Sep 17 00:00:00 2001 From: fdai7374 Date: Mon, 30 Jan 2023 21:17:11 +0100 Subject: [PATCH] refactoring: use chrono format function to format date --- src/builtins/ls.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/builtins/ls.rs b/src/builtins/ls.rs index 521c107..88a1895 100644 --- a/src/builtins/ls.rs +++ b/src/builtins/ls.rs @@ -1,6 +1,6 @@ use std::{fs::metadata, path::PathBuf, str::FromStr}; -use chrono::{DateTime, Datelike, Local, Timelike}; +use chrono::{DateTime, Datelike, Local}; use crate::error::ShellError; @@ -69,14 +69,9 @@ fn format_filesize(filesize: u64) -> String { fn format_date(date: DateTime) -> String { let now: DateTime = Local::now(); if date.day() != now.day() || date.month() != now.month() || date.year() != now.year() { - format!("{}-{:02}-{:02}", date.year(), date.month(), date.day()) + date.format("%F").to_string() } else { - format!( - "{:02}:{:02}:{:02}", - date.hour(), - date.minute(), - date.second() - ) + date.format("%T").to_string() } }