enhance(tasks): revamp time formatting
This commit is contained in:
parent
d3039cee7f
commit
8655a21396
1 changed files with 14 additions and 15 deletions
29
src/tasks.rs
29
src/tasks.rs
|
@ -736,8 +736,8 @@ impl TasksRelay {
|
||||||
"path" => self.get_task_path(Some(task.get_id())),
|
"path" => self.get_task_path(Some(task.get_id())),
|
||||||
"rpath" => self.get_relative_path(task.get_id()),
|
"rpath" => self.get_relative_path(task.get_id()),
|
||||||
// TODO format strings configurable
|
// TODO format strings configurable
|
||||||
"time" => format_secs("MMMm", self.time_tracked(task.get_id())),
|
"time" => format_secs("TTTT", self.time_tracked(task.get_id())),
|
||||||
"rtime" => format_secs("HHH:MM", self.total_time_tracked(task.get_id())),
|
"rtime" => format_secs("TT:TT", self.total_time_tracked(task.get_id())),
|
||||||
prop => task.get(prop).unwrap_or_default(),
|
prop => task.get(prop).unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1551,7 +1551,7 @@ impl Display for TasksRelay {
|
||||||
|
|
||||||
writeln!(lock,
|
writeln!(lock,
|
||||||
"{count} visible tasks{}",
|
"{count} visible tasks{}",
|
||||||
format_secs(" tracked a total of HHhMMm", total_time)
|
format_secs(" tracked a total of T", total_time)
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1593,24 +1593,23 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the given seconds according to the given format.
|
/// Formats seconds using a formatting scheme.
|
||||||
/// - MMM - minutes
|
|
||||||
/// - MM - minutes of the hour
|
|
||||||
/// - HH - hours
|
|
||||||
///
|
|
||||||
/// Returns an empty string if under one minute.
|
/// Returns an empty string if under one minute.
|
||||||
fn format_secs(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)
|
Some(secs / 60)
|
||||||
.filter(|t| t > &0)
|
.filter(|t| t > &0)
|
||||||
.map_or(String::new(), |mins| {
|
.map_or(String::new(), |mins| {
|
||||||
|
let hours = mins / 60;
|
||||||
format
|
format
|
||||||
.replace("MMM", &format!("{:3}", mins))
|
.replace("TTTT",
|
||||||
.replace("HHH", &format!("{:>3}", mins.div(60)))
|
&(if mins > 999 { format!("h{:03}", hours) }
|
||||||
.replace("HH", &format!("{:>2}", mins.div(60)))
|
else { format!("{:>3}m", mins) }))
|
||||||
.replace("H", &mins.div(60).to_string())
|
.replace("TT:TT",
|
||||||
.replace("MM", &format!("{:02}", mins.rem(60)))
|
&(if hours > 99 { format!("h{:>4}", hours) }
|
||||||
.replace("M", &mins.to_string())
|
else { format!("{:>2}:{:02}", hours, mins.rem(60)) }))
|
||||||
|
.replace("T",
|
||||||
|
&(if hours > 99 { format!("{}h", hours) }
|
||||||
|
else { format!("{}h{:02}m", hours, mins) }))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue