From 1bf9e397e52404854b9c9f022e372fe0bd14d9c3 Mon Sep 17 00:00:00 2001 From: "E.M. Gelblicht" Date: Mon, 10 Jun 2019 17:34:21 -0700 Subject: [PATCH] converted default formatting so single-digit hour times are 0-padded --- Cargo.lock | 2 ++ src/output/time.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f85be8..1c37c31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "aho-corasick" version = "0.6.9" diff --git a/src/output/time.rs b/src/output/time.rs index 6412767..9466583 100644 --- a/src/output/time.rs +++ b/src/output/time.rs @@ -122,17 +122,37 @@ impl DefaultFormat { } } + impl DefaultFormat { fn is_recent(&self, date: LocalDateTime) -> bool { date.year() == self.current_year } + fn month_to_abbrev(month: datetime::Month) -> &'static str { + match month { + datetime::Month::January => "Jan", + datetime::Month::February => "Feb", + datetime::Month::March => "Mar", + datetime::Month::April => "Apr", + datetime::Month::May => "May", + datetime::Month::June => "Jun", + datetime::Month::July => "Jul", + datetime::Month::August => "August", + datetime::Month::September => "Sep", + datetime::Month::October => "Oct", + datetime::Month::November => "Nov", + datetime::Month::December => "Dec", + } + } + #[allow(trivial_numeric_casts)] fn format_local(&self, time: Time) -> String { let date = LocalDateTime::at(time.seconds as i64); if self.is_recent(date) { - self.date_and_time.format(&date, &self.locale) + format!("{:2} {} {:02}:{:02}", + date.day(), DefaultFormat::month_to_abbrev(date.month()), + date.hour(), date.minute()) } else { self.date_and_year.format(&date, &self.locale) @@ -144,7 +164,9 @@ impl DefaultFormat { let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64)); if self.is_recent(date) { - self.date_and_time.format(&date, &self.locale) + format!("{:2} {} {:02}:{:02}", + date.day(), DefaultFormat::month_to_abbrev(date.month()), + date.hour(), date.minute()) } else { self.date_and_year.format(&date, &self.locale) @@ -153,6 +175,7 @@ impl DefaultFormat { } + #[allow(trivial_numeric_casts)] fn long_local(time: Time) -> String { let date = LocalDateTime::at(time.seconds as i64);