Add method for substracting EffortDurations
FEA: ItEr60S19TimeUnitDataType
This commit is contained in:
parent
7b939dbd8c
commit
5f386128c1
2 changed files with 28 additions and 0 deletions
|
|
@ -168,4 +168,20 @@ public class EffortDuration implements Comparable<EffortDuration> {
|
|||
return seconds == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Substracts two {@link EffortDuration}. Because {@link EffortDuration
|
||||
* durations} cannot be negative <code>this</code> must be bigger than the
|
||||
* parameter or the same
|
||||
*
|
||||
* @param duration
|
||||
* @return the result of substracting the two durations
|
||||
* @throws IllegalArgumentException
|
||||
* if the parameter is bigger than <code>this</code>
|
||||
*/
|
||||
public EffortDuration minus(EffortDuration duration) {
|
||||
Validate.isTrue(this.compareTo(duration) >= 0,
|
||||
"minued must not be smaller than subtrahend");
|
||||
return new EffortDuration(seconds - duration.seconds);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,4 +149,16 @@ public class EffortDurationTest {
|
|||
assertThat(hours(3).divideBy(4), equalTo(minutes(45)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void effortDurationCannotBeSubstractedIfMinuedIsSmallerThanSubtrahend() {
|
||||
EffortDuration threeHours = hours(3);
|
||||
threeHours.minus(threeHours.and(1, Granularity.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void effortDurationCanBeSubstracted() {
|
||||
assertThat(hours(2).minus(minutes(120)), equalTo(EffortDuration.zero()));
|
||||
assertThat(hours(2).minus(minutes(60)), equalTo(hours(1)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue