enhance(tasks): time formatting alignment
This commit is contained in:
parent
c836b0e57b
commit
01fde4c112
1 changed files with 11 additions and 6 deletions
17
src/tasks.rs
17
src/tasks.rs
|
@ -736,8 +736,8 @@ impl TasksRelay {
|
|||
"path" => self.get_task_path(Some(task.get_id())),
|
||||
"rpath" => self.get_relative_path(task.get_id()),
|
||||
// TODO format strings configurable
|
||||
"time" => display_time("MMMm", self.time_tracked(task.get_id())),
|
||||
"rtime" => display_time("HH:MM", self.total_time_tracked(task.get_id())),
|
||||
"time" => format_secs("MMMm", self.time_tracked(task.get_id())),
|
||||
"rtime" => format_secs("HHH:MM", self.total_time_tracked(task.get_id())),
|
||||
prop => task.get(prop).unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
@ -1497,8 +1497,9 @@ impl Display for TasksRelay {
|
|||
}
|
||||
writeln!(
|
||||
lock,
|
||||
"Active from {} (total tracked time {}m) - {} since {}",
|
||||
"Active from {} ({}m, total tracked time {}m) - {} since {}",
|
||||
tracking_stamp.map_or("?".to_string(), |t| format_timestamp_relative(&t)),
|
||||
tracking_stamp.map_or("?".to_string(), |t| (Timestamp::now() - t).as_u64().div(60).to_string()),
|
||||
self.time_tracked(t.get_id()) / 60,
|
||||
state,
|
||||
format_timestamp_relative(&state.get_timestamp())
|
||||
|
@ -1550,7 +1551,7 @@ impl Display for TasksRelay {
|
|||
|
||||
writeln!(lock,
|
||||
"{count} visible tasks{}",
|
||||
display_time(" tracked a total of HHhMMm", total_time)
|
||||
format_secs(" tracked a total of HHhMMm", total_time)
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1598,14 +1599,18 @@ where
|
|||
/// - HH - hours
|
||||
///
|
||||
/// Returns an empty string if under one minute.
|
||||
fn display_time(format: &str, secs: u64) -> String {
|
||||
fn format_secs(format: &str, secs: u64) -> String {
|
||||
// TODO format to only hours/days for large values
|
||||
Some(secs / 60)
|
||||
.filter(|t| t > &0)
|
||||
.map_or(String::new(), |mins| {
|
||||
format
|
||||
.replace("MMM", &format!("{:3}", mins))
|
||||
.replace("HH", &format!("{:02}", mins.div(60)))
|
||||
.replace("HHH", &format!("{:>3}", mins.div(60)))
|
||||
.replace("HH", &format!("{:>2}", mins.div(60)))
|
||||
.replace("H", &mins.div(60).to_string())
|
||||
.replace("MM", &format!("{:02}", mins.rem(60)))
|
||||
.replace("M", &mins.to_string())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue