summaryrefslogtreecommitdiffstats
path: root/src/timetype.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-25 16:37:46 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-25 16:47:48 +0200
commitcf623f13e4c9f8cc9d8b6e029bb616293427748c (patch)
tree1bd04e94f2e986a835c0cb9ae68cb7f92244cf89 /src/timetype.rs
parent6ede3e3c7e57e029026b2efd2aad216b0fa83062 (diff)
Fix weird addition bug in iterator
The problem was the matching: We matched, in the addition branches, for a pair which we then reversed. This caused a strange bug when adding a moment and a minute. The subtraction matching was wrong as well, as it also reversed the order of the arguments.
Diffstat (limited to 'src/timetype.rs')
-rw-r--r--src/timetype.rs50
1 files changed, 7 insertions, 43 deletions
diff --git a/src/timetype.rs b/src/timetype.rs
index db0c05e..cfabe1e 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -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)