summaryrefslogtreecommitdiffstats
path: root/src/timetype.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-12 15:53:07 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-12 18:06:49 +0200
commite975aa8ada208e6483a53b0bbd9f3a4df0348126 (patch)
tree0bbe168037ff3643684b31409b77050de9d194a7 /src/timetype.rs
parent4db260ccd6e0fbd41fcf7aa57b733c2cf5afd15f (diff)
Fix subtraction: Calculate first, then subtract
Diffstat (limited to 'src/timetype.rs')
-rw-r--r--src/timetype.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/timetype.rs b/src/timetype.rs
index ef3aa33..39fc997 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -602,22 +602,34 @@ fn sub(a: Box<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
(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)) => 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)) => 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)) => 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)) => 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)) => 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)) => 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::Subtraction(a, b), other) => sub(a, b)
.map(Box::new)