diff options
| author | Benedict Börger <benedict@0xb8000.de> | 2019-04-14 19:12:21 +0200 |
|---|---|---|
| committer | Benedict Börger <benedict@0xb8000.de> | 2019-04-14 19:12:21 +0200 |
| commit | f28e8a59c781f24ed9399268cc2536aad0cf534d (patch) | |
| tree | 5678dd6c12b5849ab15f9d63a49c9424d222390b /src/web_frontend/util.rs | |
| parent | 7e8656cb6d086f364baeeb79a69a04555a6fd4f6 (diff) | |
[global] update all files
Diffstat (limited to 'src/web_frontend/util.rs')
| -rw-r--r-- | src/web_frontend/util.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/web_frontend/util.rs b/src/web_frontend/util.rs new file mode 100644 index 0000000..cffef0e --- /dev/null +++ b/src/web_frontend/util.rs @@ -0,0 +1,50 @@ +use chrono::{NaiveDate, Utc}; +use chrono::Datelike; + +#[derive(Debug)] +pub struct DateRange { + start_year : i32, + start_month : u32, + end_year : i32, + end_month : u32, +} + +impl DateRange { + pub fn new(start : chrono::NaiveDate, end : chrono::NaiveDate) -> DateRange { + DateRange { + start_year : start.year(), + start_month : start.month(), + end_year : end.year(), + end_month : end.month(), + } + } +} + +impl Iterator for DateRange { + type Item = chrono::NaiveDate; + + fn next(&mut self) -> Option<Self::Item> { + println!("next called"); + if (self.start_year <= self.end_year) { + if(self.start_month <= self.end_month) { + let mut tmp = self.start_year.to_string(); + if self.start_month < 10 { + tmp.push_str("-0"); + } else { + tmp.push_str("-"); + } + tmp.push_str(&self.start_month.to_string()); + tmp.push_str("-01"); + if self.start_month < 13 { + self.start_month = self.start_month + 1; + } else { + self.start_month = 1; + self.start_year = self.start_year + 1; + } + println!("{}", tmp); + return Some(chrono::NaiveDate::parse_from_str(&tmp, "%Y-%m-%d").unwrap()) + } + } + None + } +} |
