include current time point in sum calculation

This commit is contained in:
kageru 2020-04-20 10:52:45 +02:00
parent 6075a4369f
commit 8b3b6c3d0b

View File

@ -53,7 +53,7 @@ fn read_times(path: &str) -> Option<Vec<TimePoint>> {
impl TimeSheet { impl TimeSheet {
pub fn open_or_create(path: &str) -> Self { pub fn open_or_create(path: &str) -> Self {
Self { Self {
times: read_times(path).unwrap_or_else(|| vec![TimePoint::new("Did something")]), times: read_times(path).unwrap_or_else(|| vec![TimePoint::new("start")]),
selected: 0, selected: 0,
register: None, register: None,
editing_time: false, editing_time: false,
@ -71,6 +71,7 @@ impl TimeSheet {
pub fn time_by_tasks(&self) -> String { pub fn time_by_tasks(&self) -> String {
self.times self.times
.iter() .iter()
.chain(std::iter::once(&TimePoint::new("end")))
.tuple_windows() .tuple_windows()
.map(|(prev, next)| (prev.text.clone(), next.time - prev.time)) .map(|(prev, next)| (prev.text.clone(), next.time - prev.time))
// Fold into a map to group by description. // Fold into a map to group by description.
@ -81,6 +82,7 @@ impl TimeSheet {
map map
}) })
.into_iter() .into_iter()
.filter(|(_, duration)| duration.whole_seconds() > 1)
.map(|(text, duration)| format!("{}: {}", text, format_duration(&duration))) .map(|(text, duration)| format!("{}: {}", text, format_duration(&duration)))
.join(" | ") .join(" | ")
} }
@ -90,6 +92,7 @@ impl TimeSheet {
.times .times
.iter() .iter()
.map(|tp| tp.time) .map(|tp| tp.time)
.chain(std::iter::once(OffsetDateTime::now_local().time()))
.tuple_windows() .tuple_windows()
.fold(Duration::zero(), |total, (last, next)| { .fold(Duration::zero(), |total, (last, next)| {
total + (next - last) total + (next - last)