mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-23 20:16:41 +02:00
chore: refactor datetime formatting and completion
This commit is contained in:
parent
4f15f3042b
commit
8df3b92345
1 changed files with 28 additions and 61 deletions
89
src/app.rs
89
src/app.rs
|
@ -135,6 +135,24 @@ fn get_offset_hour_minute() -> (&'static str, i32, i32) {
|
|||
(sym, h, m)
|
||||
}
|
||||
|
||||
fn get_formatted_datetime(date: &Date) -> String {
|
||||
let now = Local::now();
|
||||
let date = TimeZone::from_utc_datetime(now.offset(), date);
|
||||
let (sym, h, m) = get_offset_hour_minute();
|
||||
format!(
|
||||
"'{:04}-{:02}-{:02}T{:02}:{:02}:{:02}{}{:02}:{:02}'",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
date.second(),
|
||||
sym,
|
||||
h,
|
||||
m,
|
||||
)
|
||||
}
|
||||
|
||||
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
||||
let popup_layout = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
@ -2566,21 +2584,10 @@ impl TaskwarriorTui {
|
|||
}
|
||||
if t.due().is_some() {
|
||||
let date = t.due().unwrap();
|
||||
let now = Local::now();
|
||||
let date = TimeZone::from_utc_datetime(now.offset(), date);
|
||||
let (sym, h, m) = get_offset_hour_minute();
|
||||
s = format!(
|
||||
"{}due:'{:04}-{:02}-{:02}T{:02}:{:02}:{:02}{}{:02}:{:02}' ",
|
||||
"{}due:{} ",
|
||||
s,
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
date.second(),
|
||||
sym,
|
||||
h,
|
||||
m
|
||||
get_formatted_datetime(date);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3488,66 +3495,26 @@ impl TaskwarriorTui {
|
|||
}
|
||||
for task in tasks {
|
||||
if let Some(date) = task.due() {
|
||||
let now = Local::now();
|
||||
let date = TimeZone::from_utc_datetime(now.offset(), date);
|
||||
let s = format!(
|
||||
"'{:04}-{:02}-{:02}T{:02}:{:02}:{:02}'",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
date.second(),
|
||||
);
|
||||
self.completion_list.insert(("due".to_string(), s));
|
||||
self.completion_list
|
||||
.insert(("due".to_string(), get_formatted_datetime(date)));
|
||||
}
|
||||
}
|
||||
for task in tasks {
|
||||
if let Some(date) = task.wait() {
|
||||
let now = Local::now();
|
||||
let date = TimeZone::from_utc_datetime(now.offset(), date);
|
||||
let s = format!(
|
||||
"'{:04}-{:02}-{:02}T{:02}:{:02}:{:02}'",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
date.second(),
|
||||
);
|
||||
self.completion_list.insert(("wait".to_string(), s));
|
||||
self.completion_list
|
||||
.insert(("wait".to_string(), get_formatted_datetime(date)));
|
||||
}
|
||||
}
|
||||
for task in tasks {
|
||||
if let Some(date) = task.scheduled() {
|
||||
let now = Local::now();
|
||||
let date = TimeZone::from_utc_datetime(now.offset(), date);
|
||||
let s = format!(
|
||||
"'{:04}-{:02}-{:02}T{:02}:{:02}:{:02}'",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
date.second(),
|
||||
);
|
||||
self.completion_list.insert(("scheduled".to_string(), s));
|
||||
self.completion_list
|
||||
.insert(("scheduled".to_string(), get_formatted_datetime(date)));
|
||||
}
|
||||
}
|
||||
for task in tasks {
|
||||
if let Some(date) = task.end() {
|
||||
let now = Local::now();
|
||||
let date = TimeZone::from_utc_datetime(now.offset(), date);
|
||||
let s = format!(
|
||||
"'{:04}-{:02}-{:02}T{:02}:{:02}:{:02}'",
|
||||
date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
date.hour(),
|
||||
date.minute(),
|
||||
date.second(),
|
||||
);
|
||||
self.completion_list.insert(("end".to_string(), s));
|
||||
self.completion_list
|
||||
.insert(("end".to_string(), get_formatted_datetime(date)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue