From 608775e2b0713c67156176fba88c21d124c20ebe Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Mon, 24 Jan 2022 18:45:36 -0700 Subject: [PATCH] feat: Add more date column support --- src/app.rs | 2 +- src/task_report.rs | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index cc98aa8..56dbf49 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1110,7 +1110,7 @@ impl TaskwarriorTui { } } for (i, header) in headers.iter().enumerate() { - if header == "ID" || header == "Name" { + if i == 0 { // always give ID a couple of extra for indicator widths[i] += self.config.uda_selection_indicator.as_str().width(); // if let TableMode::MultipleSelection = self.task_table_state.mode() { diff --git a/src/task_report.rs b/src/task_report.rs index 3992967..32d666f 100644 --- a/src/task_report.rs +++ b/src/task_report.rs @@ -8,6 +8,14 @@ use task_hookrs::uda::UDAValue; use unicode_truncate::UnicodeTruncateStr; use unicode_width::UnicodeWidthStr; +pub fn format_date_time(dt: NaiveDateTime) -> String { + dt.format("%Y-%m-%d %H:%M:%S").to_string() +} + +pub fn format_date(dt: NaiveDateTime) -> String { + dt.format("%Y-%m-%d").to_string() +} + pub fn vague_format_date_time(from_dt: NaiveDateTime, to_dt: NaiveDateTime) -> String { let mut seconds = (to_dt - from_dt).num_seconds(); let minus: &str; @@ -216,18 +224,39 @@ impl TaskReportTable { Some(v) => vague_format_date_time(Local::now().naive_utc(), NaiveDateTime::new(v.date(), v.time())), None => "".to_string(), }, - "until" | "until.remaining" => match task.until() { + "due" => match task.due() { + Some(v) => format_date(NaiveDateTime::new(v.date(), v.time())), + None => "".to_string(), + }, + "until.remaining" => match task.until() { Some(v) => vague_format_date_time(Local::now().naive_utc(), NaiveDateTime::new(v.date(), v.time())), None => "".to_string(), }, + "until" => match task.until() { + Some(v) => format_date(NaiveDateTime::new(v.date(), v.time())), + None => "".to_string(), + }, "entry.age" => vague_format_date_time( NaiveDateTime::new(task.entry().date(), task.entry().time()), Local::now().naive_utc(), ), + "entry" => format_date(NaiveDateTime::new(task.entry().date(), task.entry().time())), "start.age" => match task.start() { Some(v) => vague_format_date_time(NaiveDateTime::new(v.date(), v.time()), Local::now().naive_utc()), None => "".to_string(), }, + "start" => match task.start() { + Some(v) => format_date(NaiveDateTime::new(v.date(), v.time())), + None => "".to_string(), + }, + "end.age" => match task.end() { + Some(v) => vague_format_date_time(NaiveDateTime::new(v.date(), v.time()), Local::now().naive_utc()), + None => "".to_string(), + }, + "end" => match task.end() { + Some(v) => format_date(NaiveDateTime::new(v.date(), v.time())), + None => "".to_string(), + }, "status.short" => task.status().to_string().chars().next().unwrap().to_string(), "status" => task.status().to_string(), "priority" => match task.priority() {