compact_calendar_cli/
models.rs

1use chrono::{Datelike, NaiveDate};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum WeekStart {
6    Monday,
7    Sunday,
8}
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum WeekendDisplay {
12    Dimmed,
13    Normal,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum ColorMode {
18    Normal,
19    Work,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum PastDateDisplay {
24    Strikethrough,
25    Normal,
26}
27
28#[derive(Debug, Clone)]
29pub struct DateDetail {
30    pub description: String,
31    pub color: Option<String>,
32}
33
34#[derive(Debug, Clone)]
35pub struct DateRange {
36    pub start: NaiveDate,
37    pub end: NaiveDate,
38    pub color: String,
39    pub description: Option<String>,
40}
41
42pub struct Calendar {
43    pub year: i32,
44    pub week_start: WeekStart,
45    pub weekend_display: WeekendDisplay,
46    pub color_mode: ColorMode,
47    pub past_date_display: PastDateDisplay,
48    pub details: HashMap<NaiveDate, DateDetail>,
49    pub ranges: Vec<DateRange>,
50}
51
52impl Calendar {
53    pub fn new(
54        year: i32,
55        week_start: WeekStart,
56        weekend_display: WeekendDisplay,
57        color_mode: ColorMode,
58        past_date_display: PastDateDisplay,
59        details: HashMap<NaiveDate, DateDetail>,
60        ranges: Vec<DateRange>,
61    ) -> Self {
62        Calendar {
63            year,
64            week_start,
65            weekend_display,
66            color_mode,
67            past_date_display,
68            details,
69            ranges,
70        }
71    }
72
73    pub fn get_weekday_num(&self, date: NaiveDate) -> u32 {
74        match self.week_start {
75            WeekStart::Monday => date.weekday().num_days_from_monday(),
76            WeekStart::Sunday => date.weekday().num_days_from_sunday(),
77        }
78    }
79}