From 17f683e0d30994e236545227f4f8254d28eaf388 Mon Sep 17 00:00:00 2001 From: kageru Date: Tue, 23 Jun 2020 10:07:25 +0200 Subject: [PATCH] Properly round to nearest multiple of 5 on adjustment Fixes #8 --- src/timesheet.rs | 4 ++-- src/tracc.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/timesheet.rs b/src/timesheet.rs index f53df77..38e90d0 100644 --- a/src/timesheet.rs +++ b/src/timesheet.rs @@ -83,8 +83,8 @@ impl TimeSheet { */ pub fn shift_current(&mut self, minutes: i64) { let time = &mut self.times[self.selected].time; - let current_minute = time.minute() as i64; - *time += Duration::minutes(minutes - current_minute % minutes); + *time += Duration::minutes(minutes); + *time -= Duration::minutes(time.minute() as i64 % 5) } fn current(&self) -> &TimePoint { diff --git a/src/tracc.rs b/src/tracc.rs index a859273..c83be4a 100644 --- a/src/tracc.rs +++ b/src/tracc.rs @@ -69,7 +69,10 @@ impl Tracc { } Key::Char('a') | Key::Char('A') => self.set_mode(Mode::Insert)?, Key::Char(' ') if self.focus == Focus::Top => self.todos.toggle_current(), - Key::Char('-') if self.focus == Focus::Bottom => self.times.shift_current(-5), + // Subtract only 1 minute because the number is truncated to the next multiple + // of 5 afterwards, so this is effectively a -5. + // See https://git.kageru.moe/kageru/tracc/issues/8 + Key::Char('-') if self.focus == Focus::Bottom => self.times.shift_current(-1), Key::Char('+') if self.focus == Focus::Bottom => self.times.shift_current(5), // dd Key::Char('d') => {