diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-03-08 20:07:31 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-03-08 20:09:25 -0500 |
commit | 0688cd6653e769846a4271ac2c251a7d96249396 (patch) | |
tree | 3daeae3d884d7bad15b55a495a5237007ff42950 | |
parent | 3a082edd58ecdf4db31702c6c8487c42227049a3 (diff) | |
download | nbsh-0688cd6653e769846a4271ac2c251a7d96249396.tar.gz nbsh-0688cd6653e769846a4271ac2c251a7d96249396.zip |
include the date when formatting older timestamps
-rw-r--r-- | src/format.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/format.rs b/src/format.rs index 55757c4..115ee6c 100644 --- a/src/format.rs +++ b/src/format.rs @@ -23,8 +23,16 @@ pub fn exit_status(status: std::process::ExitStatus) -> String { } pub fn time(time: time::OffsetDateTime) -> String { - let format = - time::format_description::parse("[hour]:[minute]:[second]").unwrap(); + let format = if time::OffsetDateTime::now_utc() - time + > std::time::Duration::from_secs(60 * 60 * 24) + { + time::format_description::parse( + "[year]-[month]-[day] [hour]:[minute]:[second]", + ) + .unwrap() + } else { + time::format_description::parse("[hour]:[minute]:[second]").unwrap() + }; time.format(&format).unwrap() } |