summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthewsot@outlook.com>2022-01-22 20:50:58 -0800
committerMatthew Sotoudeh <matthewsot@outlook.com>2022-01-22 20:50:58 -0800
commita2e2d88bcdbf191273caed442aad3d4ea99437e5 (patch)
treea5ae77f5efbed0c8c371d028a9015c671fe66111
parente3fe8e3ef06a0aa2188419ae722d7e6724cf2620 (diff)
Simplify the rust a bit, update the src link
-rw-r--r--src/main.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index eb676fe..593d413 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,9 +17,8 @@ struct Task {
fn parse_date_line(l: &str) -> Option<NaiveDate> {
for maybe_date_str in l.split(' ') {
- match NaiveDate::parse_from_str(maybe_date_str, "%m/%d/%y") {
- Err(_) => continue,
- Ok(date) => { return Some(date); }
+ if let Ok(date) = NaiveDate::parse_from_str(maybe_date_str, "%m/%d/%y") {
+ return Some(date);
}
};
return None;
@@ -41,14 +40,11 @@ fn parse_time(s_: &str) -> NaiveTime {
}
}
for format in formats {
- match NaiveTime::parse_from_str(&s, format) {
- Err(_) => continue,
- Ok(parsed) => {
- if !format.contains("%p") && parsed.hour() < 6 {
- return parsed + Duration::hours(12);
- }
- return parsed;
+ if let Ok(parsed) = NaiveTime::parse_from_str(&s, format) {
+ if !format.contains("%p") && parsed.hour() < 6 {
+ return parsed + Duration::hours(12);
}
+ return parsed;
}
}
panic!("Couldn't parse time {}", s);
@@ -117,10 +113,8 @@ fn handle_task_details(l: &str, t: &mut Task) {
}
fn cmp_tasks(a: &Task, b: &Task) -> Ordering {
- if a.date < b.date {
- return Ordering::Less;
- } else if b.date < a.date {
- return Ordering::Greater;
+ if a.date != b.date {
+ return if a.date < b.date { Ordering::Less } else { Ordering::Greater };
}
match [a.start_time, b.start_time] {
[None, None] => return Ordering::Equal,
@@ -323,7 +317,7 @@ fn tasks_to_html(tasks: &Vec<Task>, privacy: CalendarPrivacy) -> String {
html.push_str("</ul>");
html.push_str("</li>");
}
- html.push_str("</ul><a href=\"https://github.com/matthewsot/wtd\">src</a></body></html>");
+ html.push_str("</ul><a href=\"https://lair.masot.net/git/wtd\">src</a></body></html>");
return html;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback