From 9865b692426f6d553d458dd2e157d3c9ab7188bf Mon Sep 17 00:00:00 2001 From: fdai7375 Date: Thu, 2 Feb 2023 18:38:04 +0100 Subject: [PATCH] feat: add ls command created timestamp --- src/builtins/ls.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/builtins/ls.rs b/src/builtins/ls.rs index 1b6a891..3b921ae 100644 --- a/src/builtins/ls.rs +++ b/src/builtins/ls.rs @@ -19,7 +19,7 @@ impl Builtin for Ls { //for entry in entries.by_ref().into_iter() {} println!( - "{} | dir | size | modified | accessed |", + "{} | dir | size | modified | accessed | created |", right_padding(" filename", 20) ); @@ -47,6 +47,11 @@ impl Builtin for Ls { Err(_) => Local::now(), }; + let created: DateTime = match metadata.created() { + Ok(t) => DateTime::from(t), + Err(_) => Local::now(), + }; + let mut file_type = "unknown"; if metadata.file_type().is_dir() { file_type = "dir" @@ -63,7 +68,8 @@ impl Builtin for Ls { file_type, metadata.len(), modified, - accessed + accessed, + created ) ); } @@ -99,14 +105,16 @@ fn format_line( file_size: u64, modified: DateTime, accessed: DateTime, + created: DateTime, ) -> String { format!( - "{} | {:4} | {:6} | {} | {} |", + "{} | {:4} | {:6} | {} | {} | {} |", right_padding(file_name, max_name_len), file_type, format_filesize(file_size), right_padding(&format_date(modified), 10), - right_padding(&format_date(accessed), 10) + right_padding(&format_date(accessed), 10), + right_padding(&format_date(created), 10), ) }