From 4798795c5717b03bd21d0e7e50a3be06674101eb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Sep 2017 12:08:38 +0200 Subject: Add end of {day, hour, minute} --- src/timetype.rs | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 195 insertions(+), 13 deletions(-) (limited to 'src/timetype.rs') diff --git a/src/timetype.rs b/src/timetype.rs index a6c51d2..fe4a100 100644 --- a/src/timetype.rs +++ b/src/timetype.rs @@ -34,6 +34,9 @@ pub enum TimeType { EndOfYear(Box), EndOfMonth(Box), + EndOfDay(Box), + EndOfHour(Box), + EndOfMinute(Box), } impl Add for TimeType { @@ -177,6 +180,36 @@ impl TimeType { TimeType::EndOfMonth(Box::new(self)) } + /// Calculate the end of the day based on the current TimeType + /// + /// # Warning + /// + /// If the current TimeType does _not_ evaluate to a `TimeType::Moment`, calculating the end of + /// the day will fail + pub fn end_of_day(self) -> TimeType { + TimeType::EndOfDay(Box::new(self)) + } + + /// Calculate the end of the hour based on the current TimeType + /// + /// # Warning + /// + /// If the current TimeType does _not_ evaluate to a `TimeType::Moment`, calculating the end of + /// the hour will fail + pub fn end_of_hour(self) -> TimeType { + TimeType::EndOfHour(Box::new(self)) + } + + /// Calculate the end of the minute based on the current TimeType + /// + /// # Warning + /// + /// If the current TimeType does _not_ evaluate to a `TimeType::Moment`, calculating the end of + /// the minute will fail + pub fn end_of_minute(self) -> TimeType { + TimeType::EndOfMinute(Box::new(self)) + } + /// Get the number of seconds, if the TimeType is not a duration type, zero is returned /// /// # Warning @@ -349,11 +382,14 @@ fn do_calculate(tt: TimeType) -> Result { use timetype::TimeType as TT; match tt { - TT::Addition(a, b) => add(a, b), - TT::Subtraction(a, b) => sub(a, b), - TT::EndOfYear(inner) => end_of_year(*inner), - TT::EndOfMonth(inner) => end_of_month(*inner), - x => Ok(x) + TT::Addition(a, b) => add(a, b), + TT::Subtraction(a, b) => sub(a, b), + TT::EndOfYear(inner) => end_of_year(*inner), + TT::EndOfMonth(inner) => end_of_month(*inner), + TT::EndOfDay(inner) => end_of_day(*inner), + TT::EndOfHour(inner) => end_of_hour(*inner), + TT::EndOfMinute(inner) => end_of_minute(*inner), + x => Ok(x) } } @@ -374,8 +410,12 @@ fn end_of_year(tt: TimeType) -> Result { els @ TT::Addition(_, _) | els @ TT::Subtraction(_, _) => Err(KE::from_kind(KEK::CannotCalculateEndOfYearOn(els))), TT::Moment(m) => Ok(TT::moment(NaiveDate::from_ymd(m.year(), 12, 31).and_hms(0, 0, 0))), - TT::EndOfYear(e) => do_calculate(*e), - TT::EndOfMonth(e) => do_calculate(*e), + + TT::EndOfYear(e) => do_calculate(*e), + TT::EndOfMonth(e) => do_calculate(*e), + TT::EndOfDay(e) => do_calculate(*e), + TT::EndOfHour(e) => do_calculate(*e), + TT::EndOfMinute(e) => do_calculate(*e), } } @@ -399,8 +439,94 @@ fn end_of_month(tt: TimeType) -> Result { let last_day = get_num_of_days_in_month(m.year() as i64, m.month() as i64) as u32; Ok(TT::moment(NaiveDate::from_ymd(m.year(), m.month(), last_day).and_hms(0, 0, 0))) }, - TT::EndOfYear(e) => do_calculate(*e), - TT::EndOfMonth(e) => do_calculate(*e), + TT::EndOfYear(e) => do_calculate(*e), + TT::EndOfMonth(e) => do_calculate(*e), + TT::EndOfDay(e) => do_calculate(*e), + TT::EndOfHour(e) => do_calculate(*e), + TT::EndOfMinute(e) => do_calculate(*e), + } +} + +/// Evaluates the passed argument and if it is a `TT::Moment` it adjust its to the end of the day +/// else returns an error +/// +/// Calling a end-of-day on a end-of-day yields end-of-month applied only once. +fn end_of_day(tt: TimeType) -> Result { + use timetype::TimeType as TT; + + match try!(do_calculate(tt)) { + els @ TT::Seconds(_) | + els @ TT::Minutes(_) | + els @ TT::Hours(_) | + els @ TT::Days(_) | + els @ TT::Months(_) | + els @ TT::Years(_) | + els @ TT::Addition(_, _) | + els @ TT::Subtraction(_, _) => Err(KE::from_kind(KEK::CannotCalculateEndOfMonthOn(els))), + TT::Moment(m) => { + Ok(TT::moment(NaiveDate::from_ymd(m.year(), m.month(), m.day()).and_hms(23, 59, 59))) + }, + TT::EndOfYear(e) => do_calculate(*e), + TT::EndOfMonth(e) => do_calculate(*e), + TT::EndOfDay(e) => do_calculate(*e), + TT::EndOfHour(e) => do_calculate(*e), + TT::EndOfMinute(e) => do_calculate(*e), + } +} + +/// Evaluates the passed argument and if it is a `TT::Moment` it adjust its to the end of the hour +/// else returns an error +/// +/// Calling a end-of-hour on a end-of-hour yields end-of-month applied only once. +fn end_of_hour(tt: TimeType) -> Result { + use timetype::TimeType as TT; + + match try!(do_calculate(tt)) { + els @ TT::Seconds(_) | + els @ TT::Minutes(_) | + els @ TT::Hours(_) | + els @ TT::Days(_) | + els @ TT::Months(_) | + els @ TT::Years(_) | + els @ TT::Addition(_, _) | + els @ TT::Subtraction(_, _) => Err(KE::from_kind(KEK::CannotCalculateEndOfMonthOn(els))), + TT::Moment(m) => { + Ok(TT::moment(NaiveDate::from_ymd(m.year(), m.month(), m.day()) + .and_hms(m.hour(), 59, 59))) + }, + TT::EndOfYear(e) => do_calculate(*e), + TT::EndOfMonth(e) => do_calculate(*e), + TT::EndOfDay(e) => do_calculate(*e), + TT::EndOfHour(e) => do_calculate(*e), + TT::EndOfMinute(e) => do_calculate(*e), + } +} + +/// Evaluates the passed argument and if it is a `TT::Moment` it adjust its to the end of the +/// minute else returns an error +/// +/// Calling a end-of-minute on a end-of-minute yields end-of-month applied only once. +fn end_of_minute(tt: TimeType) -> Result { + use timetype::TimeType as TT; + + match try!(do_calculate(tt)) { + els @ TT::Seconds(_) | + els @ TT::Minutes(_) | + els @ TT::Hours(_) | + els @ TT::Days(_) | + els @ TT::Months(_) | + els @ TT::Years(_) | + els @ TT::Addition(_, _) | + els @ TT::Subtraction(_, _) => Err(KE::from_kind(KEK::CannotCalculateEndOfMonthOn(els))), + TT::Moment(m) => { + Ok(TT::moment(NaiveDate::from_ymd(m.year(), m.month(), m.day()) + .and_hms(m.hour(), m.minute(), 59))) + }, + TT::EndOfYear(e) => do_calculate(*e), + TT::EndOfMonth(e) => do_calculate(*e), + TT::EndOfDay(e) => do_calculate(*e), + TT::EndOfHour(e) => do_calculate(*e), + TT::EndOfMinute(e) => do_calculate(*e), } } @@ -449,6 +575,12 @@ fn add(a: Box, b: Box) -> Result { (TT::EndOfMonth(e), other) => Err(KE::from_kind(KEK::CannotAdd(other, TT::EndOfMonth(e)))), (other, TT::EndOfMonth(e)) => Err(KE::from_kind(KEK::CannotAdd(other, TT::EndOfMonth(e)))), + (TT::EndOfDay(e), other) => Err(KE::from_kind(KEK::CannotAdd(other, TT::EndOfDay(e)))), + (other, TT::EndOfDay(e)) => Err(KE::from_kind(KEK::CannotAdd(other, TT::EndOfDay(e)))), + + (TT::EndOfHour(e), other) => Err(KE::from_kind(KEK::CannotAdd(other, TT::EndOfHour(e)))), + (other, TT::EndOfHour(e)) => Err(KE::from_kind(KEK::CannotAdd(other, TT::EndOfHour(e)))), + others => unimplemented!(), } } @@ -466,6 +598,9 @@ fn add_to_seconds(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Seconds(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Seconds(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -484,6 +619,9 @@ fn add_to_minutes(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Minutes(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Minutes(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -502,6 +640,9 @@ fn add_to_hours(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Hours(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Hours(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Hours(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Hours(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Hours(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -520,6 +661,9 @@ fn add_to_days(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Days(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Days(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Days(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Days(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Days(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -538,6 +682,9 @@ fn add_to_months(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Months(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Months(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Months(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Months(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Months(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -556,6 +703,9 @@ fn add_to_years(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Years(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Years(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Years(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Years(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Years(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -652,6 +802,9 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotAdd(TT::Moment(mom), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Moment(mom), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Moment(mom), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Moment(mom), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotAdd(TT::Moment(mom), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -714,6 +867,14 @@ fn sub(a: Box, b: Box) -> Result { (TT::EndOfMonth(e), other) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfMonth(e)))), (other, TT::EndOfMonth(e)) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfMonth(e)))), + (TT::EndOfDay(e), other) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfDay(e)))), + (other, TT::EndOfDay(e)) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfDay(e)))), + + (TT::EndOfHour(e), other) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfHour(e)))), + (other, TT::EndOfHour(e)) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfHour(e)))), + + (TT::EndOfMinute(e), other) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfMinute(e)))), + (other, TT::EndOfMinute(e)) => Err(KE::from_kind(KEK::CannotSub(other, TT::EndOfMinute(e)))), others => unimplemented!(), } @@ -732,6 +893,9 @@ fn sub_from_seconds(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotSub(TT::Seconds(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Seconds(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Seconds(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Seconds(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Seconds(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -750,6 +914,9 @@ fn sub_from_minutes(amount: i64, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotSub(TT::Minutes(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Minutes(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Minutes(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Minutes(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Minutes(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -766,8 +933,11 @@ fn sub_from_hours(amount: i64, tt: TimeType) -> Result { 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(KE::from_kind(KEK::CannotSub(TT::Hours(amount), TT::Moment(m)))), - TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Hours(amount), TT::EndOfYear(e)))), + TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Hours(amount), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Hours(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Hours(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Hours(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -785,7 +955,10 @@ fn sub_from_days(amount: i64, tt: TimeType) -> Result { TT::Years(a) => Ok(TT::Days(amount - a * 30 * 12)), TT::Moment(m) => Err(KE::from_kind(KEK::CannotSub(TT::Days(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Days(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Days(amount), TT::EndOfMonth(e)))), + TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Days(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Days(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Days(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -803,7 +976,10 @@ fn sub_from_months(amount: i64, tt: TimeType) -> Result { TT::Years(a) => Ok(TT::Months(amount - a * 12)), TT::Moment(m) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::EndOfMonth(e)))), + TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -821,7 +997,10 @@ fn sub_from_years(amount: i64, tt: TimeType) -> Result { TT::Years(a) => Ok(TT::Years(amount - a)), TT::Moment(m) => Err(KE::from_kind(KEK::CannotSub(TT::Years(amount), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Years(amount), TT::EndOfYear(e)))), - TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Months(amount), TT::EndOfMonth(e)))), + TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Years(amount), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Years(amount), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Years(amount), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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))), } @@ -918,6 +1097,9 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result { TT::Moment(m) => Err(KE::from_kind(KEK::CannotSub(TT::Moment(mom), TT::Moment(m)))), TT::EndOfYear(e) => Err(KE::from_kind(KEK::CannotSub(TT::Moment(mom), TT::EndOfYear(e)))), TT::EndOfMonth(e) => Err(KE::from_kind(KEK::CannotSub(TT::Moment(mom), TT::EndOfMonth(e)))), + TT::EndOfDay(e) => Err(KE::from_kind(KEK::CannotSub(TT::Moment(mom), TT::EndOfDay(e)))), + TT::EndOfHour(e) => Err(KE::from_kind(KEK::CannotSub(TT::Moment(mom), TT::EndOfHour(e)))), + TT::EndOfMinute(e) => Err(KE::from_kind(KEK::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