From 59c69e7c094355e2ec7c9372e18e6da4cdbfc44f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 19 Nov 2017 15:27:23 +0100 Subject: Implement not-yet implemented match arms We can simply use our own infrastructure here to calculate the actual value of these patterns. Now things like "2015-306" (as supported by the iso8601 crate) work. --- src/parser/timetype.rs | 53 +++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/parser/timetype.rs b/src/parser/timetype.rs index 935f18a..62e321b 100644 --- a/src/parser/timetype.rs +++ b/src/parser/timetype.rs @@ -157,37 +157,50 @@ impl Into for ExactDate { ExactDate::Yesterday => timetype::TimeType::today() - timetype::TimeType::days(1), ExactDate::Tomorrow => timetype::TimeType::today() + timetype::TimeType::days(1), ExactDate::Iso8601Date(date) => { - let (year, month, day) = match date { + match date { ::iso8601::Date::YMD { year, month, day } => { - (year, month, day) + let ndt = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0); + timetype::TimeType::moment(ndt) }, - ::iso8601::Date::Week { /* year, ww, d */ .. } => { - unimplemented!() + ::iso8601::Date::Week { year, ww, d } => { + let ndt = NaiveDate::from_ymd(year, 1, 1).and_hms(0, 0, 0); + timetype::TimeType::moment(ndt) + + timetype::TimeType::weeks(ww as i64) + + timetype::TimeType::days(d as i64) }, - ::iso8601::Date::Ordinal { /* year, ddd */ .. } => { - unimplemented!() + ::iso8601::Date::Ordinal { year, ddd } => { + let ndt = NaiveDate::from_ymd(year, 1, 1).and_hms(0, 0, 0); + timetype::TimeType::moment(ndt) + + timetype::TimeType::days(ddd as i64) }, - }; - - let ndt = NaiveDate::from_ymd(year, month, day).and_hms(0, 0, 0); - timetype::TimeType::moment(ndt) + } }, ExactDate::Iso8601DateTime(::iso8601::DateTime { date, time }) => { let (hour, minute, second) = (time.hour, time.minute, time.second); - let (year, month, day) = match date { + + match date { ::iso8601::Date::YMD { year, month, day } => { - (year, month, day) + let ndt = NaiveDate::from_ymd(year, month, day).and_hms(hour, minute, second); + timetype::TimeType::moment(ndt) }, - ::iso8601::Date::Week { /* year, ww, d */ .. } => { - unimplemented!() + ::iso8601::Date::Week { year, ww, d } => { + let ndt = NaiveDate::from_ymd(year, 1, 1).and_hms(0, 0, 0); + timetype::TimeType::moment(ndt) + + timetype::TimeType::weeks(ww as i64) + + timetype::TimeType::days(d as i64) + + timetype::TimeType::hours(hour as i64) + + timetype::TimeType::minutes(minute as i64) + + timetype::TimeType::seconds(second as i64) }, - ::iso8601::Date::Ordinal { /* year, ddd */ .. } => { - unimplemented!() + ::iso8601::Date::Ordinal { year, ddd } => { + let ndt = NaiveDate::from_ymd(year, 1, 1).and_hms(0, 0, 0); + timetype::TimeType::moment(ndt) + + timetype::TimeType::days(ddd as i64) + + timetype::TimeType::hours(hour as i64) + + timetype::TimeType::minutes(minute as i64) + + timetype::TimeType::seconds(second as i64) }, - }; - - let ndt = NaiveDate::from_ymd(year, month, day).and_hms(hour, minute, second); - timetype::TimeType::moment(ndt) + } }, } } -- cgit v1.2.3