diff --git a/src/ivago/controller/pickup_times.rs b/src/ivago/controller/pickup_times.rs index aa86a1d..1f037a2 100644 --- a/src/ivago/controller/pickup_times.rs +++ b/src/ivago/controller/pickup_times.rs @@ -1,5 +1,7 @@ use super::search::Street; use chrono::NaiveDate; +use rocket::http::RawStr; +use rocket::request::FromFormValue; use std::error::Error; const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling"; @@ -13,6 +15,17 @@ pub struct PickupTime { url: String, } +impl<'v> FromFormValue<'v> for NaiveDate { + type Error = &'v RawStr; + + fn from_form_value(form_value: &'v RawStr) -> Result { + match NaiveDate::parse_from_str(form_value, "%Y-%m-%d") { + Ok(date) => Ok(date), + Err(_) => Err(form_value), + } + } +} + pub fn get_pickup_times( street: Street, number: u64,