Browse Source

refactoring: use chrono format function to format date

main
fdai7374 2 years ago
committed by fdai7451
parent
commit
6b8cf6d167
  1. 11
      src/builtins/ls.rs

11
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<Local>) -> String {
let now: DateTime<Local> = 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()
}
}

Loading…
Cancel
Save