vault_tasks_time_management/
pomodoro.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::time::Duration;

use crate::{time_management_technique::TimeManagementTechnique, State};

#[derive(Debug, PartialEq, Eq, PartialOrd)]
pub struct Pomodoro {
    focus_duration: Duration,
    break_count: usize,
    short_breaks_before_long: usize,
    short_break_duration: Duration,
    long_break_duration: Duration,
}
impl Pomodoro {
    pub fn new(
        focus_duration: Duration,
        short_breaks_before_long: usize,
        short_break_duration: Duration,
        long_break_duration: Duration,
    ) -> Self {
        Self {
            focus_duration,
            break_count: 0,
            short_breaks_before_long,
            short_break_duration,
            long_break_duration,
        }
    }

    pub fn classic_pomodoro() -> Self {
        Self {
            focus_duration: Duration::from_secs(25 * 60),
            short_break_duration: Duration::from_secs(5 * 60),
            long_break_duration: Duration::from_secs(15 * 60),
            break_count: 0,
            short_breaks_before_long: 3,
        }
    }
}
impl TimeManagementTechnique for Pomodoro {
    fn switch(&mut self, state: &Option<State>, _time_spent: Duration) -> State {
        match state {
            Some(State::Focus(_)) => {
                if self.short_breaks_before_long == self.break_count {
                    self.break_count = 0;
                    State::Break(Some(self.long_break_duration))
                } else {
                    self.break_count += 1;
                    State::Break(Some(self.short_break_duration))
                }
            }

            Some(State::Break(_)) | None => State::Focus(Some(self.focus_duration)),
        }
    }
}