summaryrefslogtreecommitdiff
path: root/src/web_frontend/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/web_frontend/util.rs')
-rw-r--r--src/web_frontend/util.rs43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/web_frontend/util.rs b/src/web_frontend/util.rs
index cffef0e..208b5b9 100644
--- a/src/web_frontend/util.rs
+++ b/src/web_frontend/util.rs
@@ -7,6 +7,7 @@ pub struct DateRange {
start_month : u32,
end_year : i32,
end_month : u32,
+ last : bool,
}
impl DateRange {
@@ -16,6 +17,7 @@ impl DateRange {
start_month : start.month(),
end_year : end.year(),
end_month : end.month(),
+ last : false,
}
}
}
@@ -24,27 +26,26 @@ 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())
- }
+ if self.last {
+ return None
}
- None
+ if self.start_year == self.end_year && self.start_month == self.end_month {
+ self.last = true;
+ }
+ 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 < 12 {
+ self.start_month = self.start_month + 1;
+ } else {
+ self.start_month = 1;
+ self.start_year = self.start_year + 1;
+ }
+ return Some(chrono::NaiveDate::parse_from_str(&tmp, "%Y-%m-%d").unwrap())
}
}