summaryrefslogtreecommitdiffstats
path: root/src/timetype.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/timetype.rs')
-rw-r--r--src/timetype.rs52
1 files changed, 8 insertions, 44 deletions
diff --git a/src/timetype.rs b/src/timetype.rs
index f9e50fa..cfabe1e 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -19,7 +19,7 @@ use indicator::{Day, Month};
use util::*;
/// A Type of Time, currently based on chrono::NaiveDateTime
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum TimeType {
Seconds(i64),
Minutes(i64),
@@ -598,22 +598,11 @@ fn add(a: Box<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
(thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotAdd(thing, TT::Moment(mom)))),
(TT::Seconds(a), other) => add_to_seconds(a, other),
- (other, TT::Seconds(a)) => add_to_seconds(a, other),
-
(TT::Minutes(a), other) => add_to_minutes(a, other),
- (other, TT::Minutes(a)) => add_to_minutes(a, other),
-
(TT::Hours(a), other) => add_to_hours(a, other),
- (other, TT::Hours(a)) => add_to_hours(a, other),
-
(TT::Days(a), other) => add_to_days(a, other),
- (other, TT::Days(a)) => add_to_days(a, other),
-
(TT::Months(a), other) => add_to_months(a, other),
- (other, TT::Months(a)) => add_to_months(a, other),
-
(TT::Years(a), other) => add_to_years(a, other),
- (other, TT::Years(a)) => add_to_years(a, other),
(TT::Addition(a, b), other) => add(a, b)
.map(Box::new)
@@ -683,7 +672,7 @@ fn add_to_minutes(amount: i64, tt: TimeType) -> Result<TimeType> {
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))),
+ TT::Subtraction(b, c) => sub_from_minutes(amount, try!(sub(b, c))),
}
}
@@ -875,37 +864,12 @@ fn sub(a: Box<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
match (*a, *b) {
(TT::Moment(mom), thing) => sub_from_moment(mom, thing),
- (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotSub(thing, TT::Moment(mom)))),
-
- (TT::Seconds(a), other) => sub_from_seconds(a, other),
- (other, TT::Seconds(a)) => do_calculate(other)
- .map(Box::new)
- .and_then(|br| sub(br, Box::new(TT::Seconds(a)))), // recurses into match branch above
-
- (TT::Minutes(a), other) => sub_from_minutes(a, other),
- (other, TT::Minutes(a)) => do_calculate(other)
- .map(Box::new)
- .and_then(|br| sub(br, Box::new(TT::Minutes(a)))), // recurses into match branch above
-
- (TT::Hours(a), other) => sub_from_hours(a, other),
- (other, TT::Hours(a)) => do_calculate(other)
- .map(Box::new)
- .and_then(|br| sub(br, Box::new(TT::Hours(a)))), // recurses into match branch above
-
- (TT::Days(a), other) => sub_from_days(a, other),
- (other, TT::Days(a)) => do_calculate(other)
- .map(Box::new)
- .and_then(|br| sub(br, Box::new(TT::Days(a)))), // recurses into match branch above
-
- (TT::Months(a), other) => sub_from_months(a, other),
- (other, TT::Months(a)) => do_calculate(other)
- .map(Box::new)
- .and_then(|br| sub(br, Box::new(TT::Months(a)))), // recurses into match branch above
-
- (TT::Years(a), other) => sub_from_years(a, other),
- (other, TT::Years(a)) => do_calculate(other)
- .map(Box::new)
- .and_then(|br| sub(br, Box::new(TT::Years(a)))), // recurses into match branch above
+ (TT::Seconds(a), other) => sub_from_seconds(a, other),
+ (TT::Minutes(a), other) => sub_from_minutes(a, other),
+ (TT::Hours(a), other) => sub_from_hours(a, other),
+ (TT::Days(a), other) => sub_from_days(a, other),
+ (TT::Months(a), other) => sub_from_months(a, other),
+ (TT::Years(a), other) => sub_from_years(a, other),
(TT::Subtraction(a, b), other) => sub(a, b)
.map(Box::new)