Properly round to nearest multiple of 5 on adjustment

Fixes #8
This commit is contained in:
kageru 2020-06-23 10:07:25 +02:00
parent 233e4ebb29
commit 17f683e0d3
Signed by untrusted user: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 6 additions and 3 deletions

@ -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 {

@ -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') => {