spreadsheet_ods_formula/
date.rs

1//!
2//! Date functions
3//!
4
5pub use crate::generated::date::*;
6
7use crate::Any;
8
9/// Parameter for DATEDIF()
10#[derive(Debug)]
11pub enum DateDifMethod {
12    /// Years
13    Years,
14    /// Months
15    Months,
16    /// Days
17    Days,
18    /// Days, ignoring months and years.
19    DaysIgnoreMonthsYears,
20    /// Months, ignoring years.
21    MonthsIgnoreYears,
22    /// Days, ignoring years.
23    DaysIgnoreYears,
24}
25
26impl Any for DateDifMethod {
27    fn formula(&self, buf: &mut String) {
28        buf.push_str(match self {
29            DateDifMethod::Years => "y",
30            DateDifMethod::Months => "m",
31            DateDifMethod::Days => "d",
32            DateDifMethod::DaysIgnoreMonthsYears => "md",
33            DateDifMethod::MonthsIgnoreYears => "ym",
34            DateDifMethod::DaysIgnoreYears => "yd",
35        });
36    }
37}
38
39/// Parameter for DAYS360()
40#[derive(Debug)]
41pub enum Days360Method {
42    /// NASD Method
43    USNasd,
44    /// European Method
45    Europe,
46}
47
48impl Any for Days360Method {
49    fn formula(&self, buf: &mut String) {
50        buf.push_str(match self {
51            Days360Method::USNasd => "FALSE()",
52            Days360Method::Europe => "TRUE()",
53        });
54    }
55}
56
57/// Parameter for WEEKDAY()
58#[derive(Debug)]
59pub enum WeekdayMethod {
60    /// Monday first, value 0.
61    Monday0,
62    /// Monday first, value 1.
63    Monday1,
64    /// Tuesday first, value 1.
65    Tuesday1,
66    /// Wednesday first, value 1.
67    Wednesday1,
68    /// Thursday first, value 1.
69    Thursday1,
70    /// Friday first, value 1.
71    Friday1,
72    /// Saturday first, value 1.
73    Saturday1,
74    /// Sunday first, value 1.
75    Sunday1,
76}
77
78impl Any for WeekdayMethod {
79    fn formula(&self, buf: &mut String) {
80        buf.push_str(match self {
81            WeekdayMethod::Monday0 => "3",
82            WeekdayMethod::Monday1 => "11",
83            WeekdayMethod::Tuesday1 => "12",
84            WeekdayMethod::Wednesday1 => "13",
85            WeekdayMethod::Thursday1 => "14",
86            WeekdayMethod::Friday1 => "15",
87            WeekdayMethod::Saturday1 => "16",
88            WeekdayMethod::Sunday1 => "17",
89        });
90    }
91}
92
93/// Parameter for WEEKNUM()
94#[derive(Debug)]
95pub enum WeeknumMethod {
96    /// First week contains Jan 1, week starts on Monday.
97    Jan1WeekMonday,
98    /// First week contains Jan 1, week starts on Tuesday.
99    Jan1WeekTuesday,
100    /// First week contains Jan 1, week starts on Wednesday.
101    Jan1WeekWednesday,
102    /// First week contains Jan 1, week starts on Thursday.
103    Jan1WeekThursday,
104    /// First week contains Jan 1, week starts on Friday.
105    Jan1WeekFriday,
106    /// First week contains Jan 1, week starts on Saturday.
107    Jan1WeekSaturday,
108    /// First week contains Jan 1, week starts on Sunday.
109    Jan1WeekSunday,
110    /// ISO week number.
111    ISOWeeknum,
112}
113
114impl Any for WeeknumMethod {
115    fn formula(&self, buf: &mut String) {
116        buf.push_str(match self {
117            WeeknumMethod::Jan1WeekMonday => "11",
118            WeeknumMethod::Jan1WeekTuesday => "12",
119            WeeknumMethod::Jan1WeekWednesday => "13",
120            WeeknumMethod::Jan1WeekThursday => "14",
121            WeeknumMethod::Jan1WeekFriday => "15",
122            WeeknumMethod::Jan1WeekSaturday => "16",
123            WeeknumMethod::Jan1WeekSunday => "17",
124            WeeknumMethod::ISOWeeknum => "21",
125        });
126    }
127}
128
129/// Parameter for YEARFRAC()
130#[derive(Debug)]
131pub enum YearFracMethod {
132    ///
133    USNasd30_360,
134    ///
135    ActualActual,
136    ///
137    Actual360,
138    ///
139    Actual365,
140    ///
141    European30_360,
142}
143
144impl Any for YearFracMethod {
145    fn formula(&self, buf: &mut String) {
146        buf.push_str(match self {
147            YearFracMethod::USNasd30_360 => "0",
148            YearFracMethod::ActualActual => "1",
149            YearFracMethod::Actual360 => "2",
150            YearFracMethod::Actual365 => "3",
151            YearFracMethod::European30_360 => "4",
152        });
153    }
154}