feat: Add more date column support

This commit is contained in:
Dheepak Krishnamurthy 2022-01-24 18:45:36 -07:00
parent 9da0f522c3
commit 608775e2b0
2 changed files with 31 additions and 2 deletions

View file

@ -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() {

View file

@ -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() {