From 07f108e1d25da387735ce2ddca04a768a2739d9f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 5 Mar 2020 19:48:58 +0100 Subject: Replace failure with thiserror Signed-off-by: Matthias Beyer --- Cargo.toml | 2 +- src/error.rs | 35 ++++--- src/iter.rs | 28 +++--- src/lib.rs | 3 +- src/matcher.rs | 9 +- src/parser/iterator.rs | 6 +- src/parser/mod.rs | 8 +- src/parser/timetype.rs | 16 +-- src/timetype.rs | 263 ++++++++++++++++++++++++------------------------- 9 files changed, 186 insertions(+), 184 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0953dcf..313669a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ repository = "https://github.com/matthiasbeyer/kairos" chrono = "0.4" nom = "3.2" iso8601 = "0.2" -failure = "0.1" +thiserror = "1" filters = { version = "0.3", optional = true } diff --git a/src/error.rs b/src/error.rs index c095000..548dcc1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,42 +1,49 @@ use timetype::TimeType; -#[derive(Debug, Clone, Eq, PartialEq, Fail)] -pub enum ErrorKind { +use thiserror::Error; - #[fail(display = "Unknown Error")] +pub type Result = ::std::result::Result; + +#[derive(Debug, Clone, Eq, PartialEq, Error)] +pub enum Error { + + #[error("Unknown Error")] UnknownError, - #[fail(display = "Cannot add: {:?} + {:?}", _0, _1)] + #[error("Cannot add: {0:?} + {1:?}")] CannotAdd(TimeType, TimeType), - #[fail(display = "Cannot subtract: {:?} - {:?}", _0, _1)] + #[error("Cannot subtract: {0:?} - {1:?}")] CannotSub(TimeType, TimeType), - #[fail(display = "The passed argument is not an amount: {:?}", _0)] + #[error("The passed argument is not an amount: {0:?}")] ArgumentErrorNotAnAmount(TimeType), - #[fail(display = "The passed argument is not a moment, but a {}", _0)] + #[error("The passed argument is not a moment, but a {0}")] ArgumentErrorNotAMoment(&'static str), - #[fail(display = "Argument Error: Cannot calculate end-of-year on a {:?}", _0)] + #[error("Argument Error: Cannot calculate end-of-year on a {0:?}")] CannotCalculateEndOfYearOn(TimeType), - #[fail(display = "Argument Error: Cannot calculate end-of-month on a {:?}", _0)] + #[error("Argument Error: Cannot calculate end-of-month on a {0:?}")] CannotCalculateEndOfMonthOn(TimeType), - #[fail(display = "Cannot compare Day to non-Moment TimeType: {:?}", _0)] + #[error("Cannot compare Day to non-Moment TimeType: {0:?}")] CannotCompareDayTo(&'static str), - #[fail(display = "Cannot compare Month to non-Moment TimeType: {:?}", _0)] + #[error("Cannot compare Month to non-Moment TimeType: {0:?}")] CannotCompareMonthTo(&'static str), - #[fail(display = "Out of bounds: {}-{}-{}T{}:{}:{}", _0, _1, _2, _3, _4, _5)] + #[error("Out of bounds: {0}-{1}-{2}T{3}:{4}:{5}")] OutOfBounds(i32, u32, u32, u32, u32, u32), - #[fail(display = "Cannot calculate date for iterator")] + #[error("Cannot calculate date for iterator")] NotADateInsideIterator, - #[fail(display = "Unknown parser error")] + #[error("Unknown parser error")] UnknownParserError, + #[error("Tokenizer error")] + NomError(#[from] nom::Err), } + diff --git a/src/iter.rs b/src/iter.rs index d3d8978..d776037 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -2,10 +2,9 @@ //! use chrono::NaiveDateTime; -use failure::Fallible as Result; -use failure::Error; -use error::ErrorKind as KEK; +use error::Result; +use error::Error; use timetype::TimeType; use matcher::Matcher; @@ -27,7 +26,7 @@ impl Iter { pub fn build(base: NaiveDateTime, inc: TimeType) -> Result { if !inc.is_a_amount() { - Err(Error::from(KEK::ArgumentErrorNotAnAmount(inc))) + Err(Error::ArgumentErrorNotAnAmount(inc)) } else { Ok(Iter { base: TimeType::moment(base), @@ -214,7 +213,7 @@ impl Iterator for UntilIter None } } else { - Some(Err(Error::from(KEK::ArgumentErrorNotAMoment(tt.name())))) + Some(Err(Error::ArgumentErrorNotAMoment(tt.name()))) } } } @@ -284,9 +283,8 @@ impl Times for I pub mod extensions { use timetype::TimeType as TT; use super::Iter; - use failure::Fallible as Result; - use failure::Error; - use error::ErrorKind as KEK; + use error::Result; + use error::Error; pub trait Minutely { fn minutely(self, i: i64) -> Result; @@ -325,7 +323,7 @@ pub mod extensions { assert!(increment.is_a_amount(), "This is a Bug, please report this!"); Iter::build(mom, increment) }, - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } @@ -340,7 +338,7 @@ pub mod extensions { assert!(increment.is_a_amount(), "This is a Bug, please report this!"); Iter::build(mom, increment) }, - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } @@ -355,7 +353,7 @@ pub mod extensions { assert!(increment.is_a_amount(), "This is a Bug, please report this!"); Iter::build(mom, increment) }, - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } @@ -371,7 +369,7 @@ pub mod extensions { assert!(increment.is_a_amount(), "This is a Bug, please report this!"); Iter::build(mom, increment) }, - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } @@ -386,7 +384,7 @@ pub mod extensions { assert!(increment.is_a_amount(), "This is a Bug, please report this!"); Iter::build(mom, increment) }, - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } @@ -401,7 +399,7 @@ pub mod extensions { assert!(increment.is_a_amount(), "This is a Bug, please report this!"); Iter::build(mom, increment) }, - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } @@ -412,7 +410,7 @@ pub mod extensions { fn every(self, inc: TT) -> Result { match self { TT::Moment(mom) => Iter::build(mom, inc), - _ => Err(Error::from(KEK::ArgumentErrorNotAnAmount(self))), + _ => Err(Error::ArgumentErrorNotAnAmount(self)), } } } diff --git a/src/lib.rs b/src/lib.rs index ae1b9c5..6479ad2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![recursion_limit="256"] -#[macro_use] -extern crate failure; +extern crate thiserror; extern crate chrono; #[macro_use] diff --git a/src/matcher.rs b/src/matcher.rs index ca4fb8d..2676201 100644 --- a/src/matcher.rs +++ b/src/matcher.rs @@ -1,9 +1,8 @@ use chrono::Datelike; -use error::ErrorKind as KEK; -use failure::Fallible as Result; -use failure::Error; +use error::Error; +use error::Result; use indicator::Day; use indicator::Month; use timetype::TimeType; @@ -19,7 +18,7 @@ impl Matcher for Day { let this : ::chrono::Weekday = self.clone().into(); tt.get_moment() .map(|mom| this == mom.weekday()) - .ok_or(Error::from(KEK::ArgumentErrorNotAMoment(tt.name()))) + .ok_or(Error::ArgumentErrorNotAMoment(tt.name())) } } @@ -29,7 +28,7 @@ impl Matcher for Month { let this : u32 = self.clone().into(); tt.get_moment() .map(|mom| this == mom.month()) - .ok_or(Error::from(KEK::ArgumentErrorNotAMoment(tt.name()))) + .ok_or(Error::ArgumentErrorNotAMoment(tt.name())) } } diff --git a/src/parser/iterator.rs b/src/parser/iterator.rs index a60892e..8661646 100644 --- a/src/parser/iterator.rs +++ b/src/parser/iterator.rs @@ -1,7 +1,7 @@ use nom::whitespace::sp; -use failure::Fallible as Result; -use failure::Error; +use error::Result; +use error::Error; use parser::timetype::*; use timetype::IntoTimeType; use timetype; @@ -93,7 +93,7 @@ impl Iterator { let into_ndt = |e: timetype::TimeType| try!(e.calculate()) .get_moment() - .ok_or(error::ErrorKind::NotADateInsideIterator) + .ok_or(Error::NotADateInsideIterator) .map_err(Error::from) .map(Clone::clone); diff --git a/src/parser/mod.rs b/src/parser/mod.rs index c6483b4..88d0020 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -49,8 +49,8 @@ use nom::IResult; mod timetype; mod iterator; -use failure::Fallible as Result; -use error::ErrorKind as KEK; +use error::Result; +use error::Error; use iter::Iter; use timetype::IntoTimeType; use parser::timetype::timetype; @@ -71,8 +71,8 @@ pub fn parse(s: &str) -> Result { IResult::Done(_, Ok(o)) => Ok(o), IResult::Done(_, Err(e)) => Err(e), IResult::Error(e) => Err(e).map_err(From::from), - IResult::Incomplete(Needed::Unknown) => Err(KEK::UnknownParserError.into()), - IResult::Incomplete(Needed::Size(_)) => Err(KEK::UnknownParserError.into()), + IResult::Incomplete(Needed::Unknown) => Err(Error::UnknownParserError), + IResult::Incomplete(Needed::Size(_)) => Err(Error::UnknownParserError), } } diff --git a/src/parser/timetype.rs b/src/parser/timetype.rs index 13f111b..1437242 100644 --- a/src/parser/timetype.rs +++ b/src/parser/timetype.rs @@ -4,11 +4,11 @@ use std::str::FromStr; use nom::digit; use nom::whitespace::sp; use chrono::NaiveDate; -use failure::Fallible as Result; use timetype::IntoTimeType; use timetype; -use error::ErrorKind as KEK; +use error::Result; +use error::Error; named!(pub integer, alt!( map_res!( @@ -192,12 +192,12 @@ impl IntoTimeType for ExactDate { ExactDate::Iso8601Date(date) => { match date { ::iso8601::Date::YMD { year, month, day } => NaiveDate::from_ymd_opt(year, month, day) - .ok_or(KEK::OutOfBounds(year, month, day, 0, 0, 0).into()) + .ok_or(Error::OutOfBounds(year, month, day, 0, 0, 0)) .map(|ndt| ndt.and_hms(0, 0, 0)) .map(timetype::TimeType::moment), ::iso8601::Date::Week { year, ww, d } => NaiveDate::from_ymd_opt(year, 1, 1) - .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into()) + .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0)) .map(|ndt| ndt.and_hms(0, 0, 0)) .map(timetype::TimeType::moment) .map(|m| { @@ -207,7 +207,7 @@ impl IntoTimeType for ExactDate { }), ::iso8601::Date::Ordinal { year, ddd } => NaiveDate::from_ymd_opt(year, 1, 1) - .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into()) + .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0)) .map(|ndt| ndt.and_hms(0, 0, 0)) .map(timetype::TimeType::moment) .map(|m| m + timetype::TimeType::days(ddd as i64)), @@ -219,11 +219,11 @@ impl IntoTimeType for ExactDate { match date { ::iso8601::Date::YMD { year, month, day } => NaiveDate::from_ymd_opt(year, month, day) .and_then(|ndt| ndt.and_hms_opt(hour, minute, second)) - .ok_or(KEK::OutOfBounds(year, month, day, hour, minute, second).into()) + .ok_or(Error::OutOfBounds(year, month, day, hour, minute, second)) .map(timetype::TimeType::moment), ::iso8601::Date::Week { year, ww, d } => NaiveDate::from_ymd_opt(year, 1, 1) - .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into()) + .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0)) .map(|ndt| ndt.and_hms(0, 0, 0)) .map(timetype::TimeType::moment) .map(|m| { @@ -236,7 +236,7 @@ impl IntoTimeType for ExactDate { }), ::iso8601::Date::Ordinal { year, ddd } => NaiveDate::from_ymd_opt(year, 1, 1) - .ok_or(KEK::OutOfBounds(year, 1, 1, 0, 0, 0).into()) + .ok_or(Error::OutOfBounds(year, 1, 1, 0, 0, 0)) .map(|ndt| ndt.and_hms(0, 0, 0)) .map(timetype::TimeType::moment) .map(|m| { diff --git a/src/timetype.rs b/src/timetype.rs index 3d02c57..e49a5ea 100644 --- a/src/timetype.rs +++ b/src/timetype.rs @@ -5,15 +5,14 @@ use chrono::NaiveDateTime; use chrono::NaiveDate; use chrono::Datelike; use chrono::Timelike; -use failure::Fallible as Result; -use failure::Error; use std::ops::Add; use std::ops::AddAssign; use std::ops::Sub; use std::ops::SubAssign; -use error::ErrorKind as KEK; +use error::Result; +use error::Error; use indicator::{Day, Month}; use util::*; @@ -395,7 +394,7 @@ impl TimeType { match *self { TT::Moment(m) => Ok(m.weekday() == d.into()), - _ => Err(Error::from(KEK::CannotCompareDayTo(self.name()))), + _ => Err(Error::CannotCompareDayTo(self.name())), } } @@ -406,7 +405,7 @@ impl TimeType { match *self { TT::Moment(m) => Ok(m.month() == month.into()), - _ => Err(Error::from(KEK::CannotCompareMonthTo(self.name()))), + _ => Err(Error::CannotCompareMonthTo(self.name())), } } @@ -481,11 +480,11 @@ fn end_of_year(tt: TimeType) -> Result { els @ TT::Months(_) | els @ TT::Years(_) | els @ TT::Addition(_, _) | - els @ TT::Subtraction(_, _) => Err(Error::from(KEK::CannotCalculateEndOfYearOn(els))), + els @ TT::Subtraction(_, _) => Err(Error::CannotCalculateEndOfYearOn(els)), TT::Moment(m) => NaiveDate::from_ymd_opt(m.year(), 12, 31) .map(|nd| nd.and_hms(0, 0, 0)) .map(TT::moment) - .ok_or(KEK::OutOfBounds(m.year() as i32, 12, 31, 0, 0, 0)) + .ok_or(Error::OutOfBounds(m.year() as i32, 12, 31, 0, 0, 0)) .map_err(Error::from), TT::EndOfYear(e) => do_calculate(*e), @@ -511,13 +510,13 @@ fn end_of_month(tt: TimeType) -> Result { els @ TT::Months(_) | els @ TT::Years(_) | els @ TT::Addition(_, _) | - els @ TT::Subtraction(_, _) => Err(Error::from(KEK::CannotCalculateEndOfMonthOn(els))), + els @ TT::Subtraction(_, _) => Err(Error::CannotCalculateEndOfMonthOn(els)), TT::Moment(m) => { let last_day = get_num_of_days_in_month(m.year() as i64, m.month() as i64) as u32; NaiveDate::from_ymd_opt(m.year(), m.month(), last_day) .map(|nd| nd.and_hms(0, 0, 0)) .map(TT::moment) - .ok_or(KEK::OutOfBounds(m.year() as i32, m.month() as u32, last_day, 0, 0, 0)) + .ok_or(Error::OutOfBounds(m.year() as i32, m.month() as u32, last_day, 0, 0, 0)) .map_err(Error::from) }, TT::EndOfYear(e) => do_calculate(*e), @@ -543,11 +542,11 @@ fn end_of_day(tt: TimeType) -> Result { els @ TT::Months(_) | els @ TT::Years(_) | els @ TT::Addition(_, _) | - els @ TT::Subtraction(_, _) => Err(Error::from(KEK::CannotCalculateEndOfMonthOn(els))), + els @ TT::Subtraction(_, _) => Err(Error::CannotCalculateEndOfMonthOn(els)), TT::Moment(m) => NaiveDate::from_ymd_opt(m.year(), m.month(), m.day()) .map(|nd| nd.and_hms(23, 59, 59)) .map(TT::moment) - .ok_or(KEK::OutOfBounds(m.year() as i32, m.month() as u32, m.day() as u32, 23, 59, 59)) + .ok_or(Error::OutOfBounds(m.year() as i32, m.month() as u32, m.day() as u32, 23, 59, 59)) .map_err(Error::from), TT::EndOfYear(e) => do_calculate(*e), TT::EndOfMonth(e) => do_calculate(*e), @@ -572,11 +571,11 @@ fn end_of_hour(tt: TimeType) -> Result { els @ TT::Months(_) | els @ TT::Years(_) | els @ TT::Addition(_, _) | - els @ TT::Subtraction(_, _) => Err(Error::from(KEK::CannotCalculateEndOfMonthOn(els))), + els @ TT::Subtraction(_, _) => Err(Error::CannotCalculateEndOfMonthOn(els)), TT::Moment(m) => NaiveDate::from_ymd_opt(m.year(), m.month(), m.day()) .and_then(|nd| nd.and_hms_opt(m.hour(), 59, 59)) .map(TT::moment) - .ok_or(KEK::OutOfBounds(m.year() as i32, m.month() as u32, m.day() as u32, m.hour() as u32, 59, 59)) + .ok_or(Error::OutOfBounds(m.year() as i32, m.month() as u32, m.day() as u32, m.hour() as u32, 59, 59)) .map_err(Error::from), TT::EndOfYear(e) => do_calculate(*e), TT::EndOfMonth(e) => do_calculate(*e), @@ -601,11 +600,11 @@ fn end_of_minute(tt: TimeType) -> Result { els @ TT::Months(_) | els @ TT::Years(_) | els @ TT::Addition(_, _) | - els @ TT::Subtraction(_, _) => Err(Error::from(KEK::CannotCalculateEndOfMonthOn(els))), + els @ TT::Subtraction(_, _) => Err(Error::CannotCalculateEndOfMonthOn(els)), TT::Moment(m) => NaiveDate::from_ymd_opt(m.year(), m.month(), m.day()) .and_then(|nd| nd.and_hms_opt(m.hour(), m.minute(), 59)) .map(TT::moment) - .ok_or(KEK::OutOfBounds(m.year() as i32, m.month() as u32, m.day() as u32, m.hour() as u32, m.minute() as u32, 59 as u32)) + .ok_or(Error::OutOfBounds(m.year() as i32, m.month() as u32, m.day() as u32, m.hour() as u32, m.minute() as u32, 59 as u32)) .map_err(Error::from), TT::EndOfYear(e) => do_calculate(*e), TT::EndOfMonth(e) => do_calculate(*e), @@ -620,7 +619,7 @@ fn add(a: Box, b: Box) -> Result { match (*a, *b) { (TT::Moment(mom), thing) => add_to_moment(mom, thing), - (thing, TT::Moment(mom)) => Err(Error::from(KEK::CannotAdd(thing, TT::Moment(mom)))), + (thing, TT::Moment(mom)) => Err(Error::CannotAdd(thing, TT::Moment(mom))), (TT::Seconds(a), other) => add_to_seconds(a, other), (TT::Minutes(a), other) => add_to_minutes(a, other), @@ -643,21 +642,21 @@ fn add(a: Box, b: Box) -> Result { .and_then(|bx| add(Box::new(other), bx)) .and_then(|rx| sub(Box::new(rx), b)), - (TT::EndOfYear(e), other) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfYear(e)))), - (other, TT::EndOfYear(e)) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfYear(e)))), + (TT::EndOfYear(e), other) => Err(Error::CannotAdd(other, TT::EndOfYear(e))), + (other, TT::EndOfYear(e)) => Err(Error::CannotAdd(other, TT::EndOfYear(e))), - (TT::EndOfMonth(e), other) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfMonth(e)))), - (other, TT::EndOfMonth(e)) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfMonth(e)))), + (TT::EndOfMonth(e), other) => Err(Error::CannotAdd(other, TT::EndOfMonth(e))), + (other, TT::EndOfMonth(e)) => Err(Error::CannotAdd(other, TT::EndOfMonth(e))), - (TT::EndOfDay(e), other) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfDay(e)))), - (other, TT::EndOfDay(e)) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfDay(e)))), + (TT::EndOfDay(e), other) => Err(Error::CannotAdd(other, TT::EndOfDay(e))), + (other, TT::EndOfDay(e)) => Err(Error::CannotAdd(other, TT::EndOfDay(e))), - (TT::EndOfHour(e), other) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfHour(e)))), - (other, TT::EndOfHour(e)) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfHour(e)))), + (TT::EndOfHour(e), other) => Err(Error::CannotAdd(other, TT::EndOfHour(e))), + (other, TT::EndOfHour(e)) => Err(Error::CannotAdd(other, TT::EndOfHour(e))), - (TT::EndOfMinute(e), other) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfMinute(e)))), + (TT::EndOfMinute(e), other) => Err(Error::CannotAdd(other, TT::EndOfMinute(e))), // unreachable, just for completeness: - //(other, TT::EndOfMinute(e)) => Err(Error::from(KEK::CannotAdd(other, TT::EndOfMinute(e)))), + //(other, TT::EndOfMinute(e)) => Err(Error::CannotAdd(other, TT::EndOfMinute(e))), } } @@ -671,12 +670,12 @@ fn add_to_seconds(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Seconds(a * 60 * 60 * 24 + amount)), TT::Months(a) => Ok(TT::Seconds(a * 60 * 60 * 24 * 30 + amount)), TT::Years(a) => Ok(TT::Seconds(a * 60 * 60 * 24 * 30 * 12 + amount)), - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Seconds(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Seconds(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => add_to_seconds(amount, try!(add(b, c))), TT::Subtraction(b, c) => add_to_seconds(amount, try!(sub(b, c))), } @@ -692,12 +691,12 @@ fn add_to_minutes(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Minutes(a * 60 * 24 + amount)), TT::Months(a) => Ok(TT::Minutes(a * 60 * 24 * 30 + amount)), TT::Years(a) => Ok(TT::Minutes(a * 60 * 24 * 30 * 12 + amount)), - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Minutes(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Minutes(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => add_to_minutes(amount, try!(add(b, c))), TT::Subtraction(b, c) => add_to_minutes(amount, try!(sub(b, c))), } @@ -713,12 +712,12 @@ fn add_to_hours(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Hours( a * 24 + amount)), TT::Months(a) => Ok(TT::Hours( a * 24 * 30 + amount)), TT::Years(a) => Ok(TT::Hours( a * 24 * 30 * 12 + amount)), - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Hours(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Hours(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Hours(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Hours(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Hours(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Hours(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Hours(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => add_to_hours(amount, try!(add(b, c))), TT::Subtraction(b, c) => add_to_hours(amount, try!(sub(b, c))), } @@ -734,12 +733,12 @@ fn add_to_days(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Days( a + amount)), TT::Months(a) => Ok(TT::Days( a * 30 + amount)), TT::Years(a) => Ok(TT::Days( a * 30 * 12 + amount)), - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Days(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Days(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Days(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Days(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Days(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Days(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Days(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => add_to_days(amount, try!(add(b, c))), TT::Subtraction(b, c) => add_to_days(amount, try!(sub(b, c))), } @@ -755,12 +754,12 @@ fn add_to_months(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Days( a + amount * 30)), TT::Months(a) => Ok(TT::Months( a + amount)), TT::Years(a) => Ok(TT::Months( a * 12 + amount)), - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Months(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Months(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Months(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Months(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Months(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Months(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Months(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => add_to_months(amount, try!(add(b, c))), TT::Subtraction(b, c) => add_to_months(amount, try!(sub(b, c))), } @@ -776,12 +775,12 @@ fn add_to_years(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Days( a + amount * 12 * 30)), TT::Months(a) => Ok(TT::Months( a + amount * 12)), TT::Years(a) => Ok(TT::Years( a + amount)), - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Years(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Years(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Years(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Years(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Years(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Years(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Years(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => add_to_years(amount, try!(add(b, c))), TT::Subtraction(b, c) => add_to_years(amount, try!(sub(b, c))), } @@ -803,7 +802,7 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -819,7 +818,7 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -835,7 +834,7 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -851,7 +850,7 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -867,7 +866,7 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -883,16 +882,16 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, - TT::Moment(m) => Err(Error::from(KEK::CannotAdd(TT::Moment(mom), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotAdd(TT::Moment(mom), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotAdd(TT::Moment(mom), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotAdd(TT::Moment(mom), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotAdd(TT::Moment(mom), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotAdd(TT::Moment(mom), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotAdd(TT::Moment(mom), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfMinute(e))), TT::Addition(a, b) => add_to_moment(mom, try!(add(a, b))), TT::Subtraction(a, b) => add_to_moment(mom, try!(sub(a, b))), } @@ -924,21 +923,21 @@ fn sub(a: Box, b: Box) -> Result { .and_then(|bx| sub(Box::new(other), bx)) .and_then(|rx| add(Box::new(rx), b)), - (TT::EndOfYear(e), other) => Err(Error::from(KEK::CannotSub(other, TT::EndOfYear(e)))), - (other, TT::EndOfYear(e)) => Err(Error::from(KEK::CannotSub(other, TT::EndOfYear(e)))), + (TT::EndOfYear(e), other) => Err(Error::CannotSub(other, TT::EndOfYear(e))), + (other, TT::EndOfYear(e)) => Err(Error::CannotSub(other, TT::EndOfYear(e))), - (TT::EndOfMonth(e), other) => Err(Error::from(KEK::CannotSub(other, TT::EndOfMonth(e)))), - (other, TT::EndOfMonth(e)) => Err(Error::from(KEK::CannotSub(other, TT::EndOfMonth(e)))), + (TT::EndOfMonth(e), other) => Err(Error::CannotSub(other, TT::EndOfMonth(e))), + (other, TT::EndOfMonth(e)) => Err(Error::CannotSub(other, TT::EndOfMonth(e))), - (TT::EndOfDay(e), other) => Err(Error::from(KEK::CannotSub(other, TT::EndOfDay(e)))), - (other, TT::EndOfDay(e)) => Err(Error::from(KEK::CannotSub(other, TT::EndOfDay(e)))), + (TT::EndOfDay(e), other) => Err(Error::CannotSub(other, TT::EndOfDay(e))), + (other, TT::EndOfDay(e)) => Err(Error::CannotSub(other, TT::EndOfDay(e))), - (TT::EndOfHour(e), other) => Err(Error::from(KEK::CannotSub(other, TT::EndOfHour(e)))), - (other, TT::EndOfHour(e)) => Err(Error::from(KEK::CannotSub(other, TT::EndOfHour(e)))), + (TT::EndOfHour(e), other) => Err(Error::CannotSub(other, TT::EndOfHour(e))), + (other, TT::EndOfHour(e)) => Err(Error::CannotSub(other, TT::EndOfHour(e))), - (TT::EndOfMinute(e), other) => Err(Error::from(KEK::CannotSub(other, TT::EndOfMinute(e)))), + (TT::EndOfMinute(e), other) => Err(Error::CannotSub(other, TT::EndOfMinute(e))), // unreachable, but for completeness - //(other, TT::EndOfMinute(e)) => Err(Error::from(KEK::CannotSub(other, TT::EndOfMinute(e)))), + //(other, TT::EndOfMinute(e)) => Err(Error::CannotSub(other, TT::EndOfMinute(e))), } } @@ -952,12 +951,12 @@ fn sub_from_seconds(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Seconds(amount - a * 60 * 60 * 24)), TT::Months(a) => Ok(TT::Seconds(amount - a * 60 * 60 * 24 * 30)), TT::Years(a) => Ok(TT::Seconds(amount - a * 60 * 60 * 24 * 30 * 12)), - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Seconds(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Seconds(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Seconds(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Seconds(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Seconds(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Seconds(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Seconds(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => sub_from_seconds(amount, try!(add(b, c))), TT::Subtraction(b, c) => sub_from_seconds(amount, try!(sub(b, c))), } @@ -973,12 +972,12 @@ fn sub_from_minutes(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Minutes(amount - a * 60 * 24)), TT::Months(a) => Ok(TT::Minutes(amount - a * 60 * 24 * 30)), TT::Years(a) => Ok(TT::Minutes(amount - a * 60 * 24 * 30 * 12)), - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Minutes(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Minutes(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Minutes(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Minutes(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Minutes(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Minutes(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Minutes(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => sub_from_minutes(amount, try!(add(b, c))), TT::Subtraction(b, c) => sub_from_minutes(amount, try!(sub(b, c))), } @@ -994,12 +993,12 @@ fn sub_from_hours(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Hours(amount - a * 24)), TT::Months(a) => Ok(TT::Hours(amount - a * 24 * 30)), TT::Years(a) => Ok(TT::Hours(amount - a * 24 * 30 * 12)), - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Hours(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Hours(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Hours(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Hours(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Hours(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Hours(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Hours(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => sub_from_hours(amount, try!(add(b, c))), TT::Subtraction(b, c) => sub_from_hours(amount, try!(sub(b, c))), } @@ -1015,12 +1014,12 @@ fn sub_from_days(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Days(amount - a)), TT::Months(a) => Ok(TT::Days(amount - a * 30)), TT::Years(a) => Ok(TT::Days(amount - a * 30 * 12)), - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Days(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Days(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Days(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Days(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Days(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Days(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Days(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => sub_from_days(amount, try!(add(b, c))), TT::Subtraction(b, c) => sub_from_days(amount, try!(sub(b, c))), } @@ -1036,12 +1035,12 @@ fn sub_from_months(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Days(amount * 30 - a)), TT::Months(a) => Ok(TT::Months(amount - a)), TT::Years(a) => Ok(TT::Months(amount - a * 12)), - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Months(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Months(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Months(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Months(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Months(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Months(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Months(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => sub_from_months(amount, try!(add(b, c))), TT::Subtraction(b, c) => sub_from_months(amount, try!(sub(b, c))), } @@ -1057,12 +1056,12 @@ fn sub_from_years(amount: i64, tt: TimeType) -> Result { TT::Days(a) => Ok(TT::Days(amount * 12 * 30 - a)), TT::Months(a) => Ok(TT::Months(amount * 12 - a)), TT::Years(a) => Ok(TT::Years(amount - a)), - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Years(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Years(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Years(amount), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Years(amount), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Years(amount), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Years(amount), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Years(amount), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfMinute(e))), TT::Addition(b, c) => sub_from_years(amount, try!(add(b, c))), TT::Subtraction(b, c) => sub_from_years(amount, try!(sub(b, c))), } @@ -1084,7 +1083,7 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -1100,7 +1099,7 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -1116,7 +1115,7 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -1132,7 +1131,7 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -1148,7 +1147,7 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, @@ -1164,16 +1163,16 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { let tt = NaiveDate::from_ymd_opt(y as i32, mo as u32, d as u32) .and_then(|nd| nd.and_hms_opt(h as u32, mi as u32, s as u32)) - .ok_or(KEK::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) + .ok_or(Error::OutOfBounds(y as i32, mo as u32, h as u32, h as u32, mi as u32, s as u32)) .map_err(Error::from)?; Ok(TimeType::moment(tt)) }, - TT::Moment(m) => Err(Error::from(KEK::CannotSub(TT::Moment(mom), TT::Moment(m)))), - TT::EndOfYear(e) => Err(Error::from(KEK::CannotSub(TT::Moment(mom), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(Error::from(KEK::CannotSub(TT::Moment(mom), TT::EndOfMonth(e)))), - TT::EndOfDay(e) => Err(Error::from(KEK::CannotSub(TT::Moment(mom), TT::EndOfDay(e)))), - TT::EndOfHour(e) => Err(Error::from(KEK::CannotSub(TT::Moment(mom), TT::EndOfHour(e)))), - TT::EndOfMinute(e) => Err(Error::from(KEK::CannotSub(TT::Moment(mom), TT::EndOfMinute(e)))), + TT::Moment(m) => Err(Error::CannotSub(TT::Moment(mom), TT::Moment(m))), + TT::EndOfYear(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfYear(e))), + TT::EndOfMonth(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfMonth(e))), + TT::EndOfDay(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfDay(e))), + TT::EndOfHour(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfHour(e))), + TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfMinute(e))), TT::Addition(a, b) => sub_from_moment(mom, try!(add(a, b))), TT::Subtraction(a, b) => sub_from_moment(mom, try!(sub(a, b))), } -- cgit v1.2.3 From 2a75e24c9834b2f4599e0b310454a72e0b59debb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 5 Mar 2020 19:51:13 +0100 Subject: Replace try!() with ? operator Signed-off-by: Matthias Beyer --- src/parser/iterator.rs | 10 ++++---- src/timetype.rs | 66 +++++++++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/parser/iterator.rs b/src/parser/iterator.rs index 8661646..be814b0 100644 --- a/src/parser/iterator.rs +++ b/src/parser/iterator.rs @@ -91,7 +91,7 @@ impl Iterator { Iterspec::Yearly => unit_to_amount(1, Unit::Year), }; - let into_ndt = |e: timetype::TimeType| try!(e.calculate()) + let into_ndt = |e: timetype::TimeType| e.calculate()? .get_moment() .ok_or(Error::NotADateInsideIterator) .map_err(Error::from) @@ -99,22 +99,22 @@ impl Iterator { match self.2 { Some(UntilSpec::Exact(e)) => { - let base = try!(into_ndt(self.0.into_timetype()?)); - let e = try!(into_ndt(e.into_timetype()?)); + let base = into_ndt(self.0.into_timetype()?)?; + let e = into_ndt(e.into_timetype()?)?; iter::Iter::build(base, recur) .map(|it| UserIterator::UntilIterator(it.until(e))) }, Some(UntilSpec::Times(i)) => { - let base = try!(into_ndt(self.0.into_timetype()?)); + let base = into_ndt(self.0.into_timetype()?)?; iter::Iter::build(base, recur) .map(|it| it.times(i)) .map(UserIterator::TimesIter) }, None => { - let base = try!(into_ndt(self.0.into_timetype()?)); + let base = into_ndt(self.0.into_timetype()?)?; iter::Iter::build(base, recur) .map(UserIterator::Iterator) }, diff --git a/src/timetype.rs b/src/timetype.rs index e49a5ea..8fdd1d1 100644 --- a/src/timetype.rs +++ b/src/timetype.rs @@ -472,7 +472,7 @@ fn do_calculate(tt: TimeType) -> Result { fn end_of_year(tt: TimeType) -> Result { use timetype::TimeType as TT; - match try!(do_calculate(tt)) { + match do_calculate(tt)? { els @ TT::Seconds(_) | els @ TT::Minutes(_) | els @ TT::Hours(_) | @@ -502,7 +502,7 @@ fn end_of_year(tt: TimeType) -> Result { fn end_of_month(tt: TimeType) -> Result { use timetype::TimeType as TT; - match try!(do_calculate(tt)) { + match do_calculate(tt)? { els @ TT::Seconds(_) | els @ TT::Minutes(_) | els @ TT::Hours(_) | @@ -534,7 +534,7 @@ fn end_of_month(tt: TimeType) -> Result { fn end_of_day(tt: TimeType) -> Result { use timetype::TimeType as TT; - match try!(do_calculate(tt)) { + match do_calculate(tt)? { els @ TT::Seconds(_) | els @ TT::Minutes(_) | els @ TT::Hours(_) | @@ -563,7 +563,7 @@ fn end_of_day(tt: TimeType) -> Result { fn end_of_hour(tt: TimeType) -> Result { use timetype::TimeType as TT; - match try!(do_calculate(tt)) { + match do_calculate(tt)? { els @ TT::Seconds(_) | els @ TT::Minutes(_) | els @ TT::Hours(_) | @@ -592,7 +592,7 @@ fn end_of_hour(tt: TimeType) -> Result { fn end_of_minute(tt: TimeType) -> Result { use timetype::TimeType as TT; - match try!(do_calculate(tt)) { + match do_calculate(tt)? { els @ TT::Seconds(_) | els @ TT::Minutes(_) | els @ TT::Hours(_) | @@ -676,8 +676,8 @@ fn add_to_seconds(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => add_to_seconds(amount, try!(add(b, c))), - TT::Subtraction(b, c) => add_to_seconds(amount, try!(sub(b, c))), + TT::Addition(b, c) => add_to_seconds(amount, add(b, c)?), + TT::Subtraction(b, c) => add_to_seconds(amount, sub(b, c)?), } } @@ -697,8 +697,8 @@ fn add_to_minutes(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => add_to_minutes(amount, try!(add(b, c))), - TT::Subtraction(b, c) => add_to_minutes(amount, try!(sub(b, c))), + TT::Addition(b, c) => add_to_minutes(amount, add(b, c)?), + TT::Subtraction(b, c) => add_to_minutes(amount, sub(b, c)?), } } @@ -718,8 +718,8 @@ fn add_to_hours(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => add_to_hours(amount, try!(add(b, c))), - TT::Subtraction(b, c) => add_to_hours(amount, try!(sub(b, c))), + TT::Addition(b, c) => add_to_hours(amount, add(b, c)?), + TT::Subtraction(b, c) => add_to_hours(amount, sub(b, c)?), } } @@ -739,8 +739,8 @@ fn add_to_days(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => add_to_days(amount, try!(add(b, c))), - TT::Subtraction(b, c) => add_to_days(amount, try!(sub(b, c))), + TT::Addition(b, c) => add_to_days(amount, add(b, c)?), + TT::Subtraction(b, c) => add_to_days(amount, sub(b, c)?), } } @@ -760,8 +760,8 @@ fn add_to_months(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => add_to_months(amount, try!(add(b, c))), - TT::Subtraction(b, c) => add_to_months(amount, try!(sub(b, c))), + TT::Addition(b, c) => add_to_months(amount, add(b, c)?), + TT::Subtraction(b, c) => add_to_months(amount, sub(b, c)?), } } @@ -781,8 +781,8 @@ fn add_to_years(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => add_to_years(amount, try!(add(b, c))), - TT::Subtraction(b, c) => add_to_years(amount, try!(sub(b, c))), + TT::Addition(b, c) => add_to_years(amount, add(b, c)?), + TT::Subtraction(b, c) => add_to_years(amount, sub(b, c)?), } } @@ -892,8 +892,8 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfMinute(e))), - TT::Addition(a, b) => add_to_moment(mom, try!(add(a, b))), - TT::Subtraction(a, b) => add_to_moment(mom, try!(sub(a, b))), + TT::Addition(a, b) => add_to_moment(mom, add(a, b)?), + TT::Subtraction(a, b) => add_to_moment(mom, sub(a, b)?), } } @@ -957,8 +957,8 @@ fn sub_from_seconds(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => sub_from_seconds(amount, try!(add(b, c))), - TT::Subtraction(b, c) => sub_from_seconds(amount, try!(sub(b, c))), + TT::Addition(b, c) => sub_from_seconds(amount, add(b, c)?), + TT::Subtraction(b, c) => sub_from_seconds(amount, sub(b, c)?), } } @@ -978,8 +978,8 @@ fn sub_from_minutes(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => sub_from_minutes(amount, try!(add(b, c))), - TT::Subtraction(b, c) => sub_from_minutes(amount, try!(sub(b, c))), + TT::Addition(b, c) => sub_from_minutes(amount, add(b, c)?), + TT::Subtraction(b, c) => sub_from_minutes(amount, sub(b, c)?), } } @@ -999,8 +999,8 @@ fn sub_from_hours(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => sub_from_hours(amount, try!(add(b, c))), - TT::Subtraction(b, c) => sub_from_hours(amount, try!(sub(b, c))), + TT::Addition(b, c) => sub_from_hours(amount, add(b, c)?), + TT::Subtraction(b, c) => sub_from_hours(amount, sub(b, c)?), } } @@ -1020,8 +1020,8 @@ fn sub_from_days(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => sub_from_days(amount, try!(add(b, c))), - TT::Subtraction(b, c) => sub_from_days(amount, try!(sub(b, c))), + TT::Addition(b, c) => sub_from_days(amount, add(b, c)?), + TT::Subtraction(b, c) => sub_from_days(amount, sub(b, c)?), } } @@ -1041,8 +1041,8 @@ fn sub_from_months(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfHour(e))), TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfMinute(e))), - TT::Addition(b, c) => sub_from_months(amount, try!(add(b, c))), - TT::Subtraction(b, c) => sub_from_months(amount, try!(sub(b, c))), + TT::Addition(b, c) => sub_from_months(amount, add(b, c)?), + TT::Subtraction(b, c) => sub_from_months(amount, sub(b, c)?), } } @@ -1062,8 +1062,8 @@ fn sub_from_years(amount: i64, tt: TimeType) -> Result { TT::EndOfDay(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfDay(e))), TT::EndOfHour(e) => Err(Er