fix: Convert to local time for formatting

This commit is contained in:
Dheepak Krishnamurthy 2022-03-02 16:24:30 -07:00
parent 9517bc1966
commit ebd9c6f770

View file

@ -9,14 +9,18 @@ use unicode_truncate::UnicodeTruncateStr;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
pub fn format_date_time(dt: NaiveDateTime) -> String { pub fn format_date_time(dt: NaiveDateTime) -> String {
let dt = Local.from_local_datetime(&dt).unwrap();
dt.format("%Y-%m-%d %H:%M:%S").to_string() dt.format("%Y-%m-%d %H:%M:%S").to_string()
} }
pub fn format_date(dt: NaiveDateTime) -> String { pub fn format_date(dt: NaiveDateTime) -> String {
let dt = Local.from_local_datetime(&dt).unwrap();
dt.format("%Y-%m-%d").to_string() dt.format("%Y-%m-%d").to_string()
} }
pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime) -> String { pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime) -> String {
let to_dt = Local.from_local_datetime(&to_dt).unwrap();
let from_dt = Local.from_local_datetime(&from_dt).unwrap();
let mut seconds = (to_dt - from_dt).num_seconds(); let mut seconds = (to_dt - from_dt).num_seconds();
let minus: &str; let minus: &str;