Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1-rc-1
-
Fix Version/s: 1.1-rc-2
-
Component/s: None
-
Labels:None
-
Environment:Windows XP. java version "1.5.0_08". Ant 1.7
-
Testcase included:yes
-
Number of attachments :
Description
Subtracting 2.minutes from 12:02:00 AM results in 23:01:00 of the previous day... yet subtracting 120.seconds correctly results in 12:00:00.
Also, subtractiong 2.hours from 2:00:00 AM results in the previous day... yet subtracting 7200.seconds correctly results in 12:00:00
Here is the code of two test cases that show the error. The commented out lines should be passing.
void testDurationArithmeticOnMinutes() {
use(TimeCategory) {
def midnight = new Date(100, 0, 1, 0, 0, 0)
def oneMinutePastMidnight = new Date(100, 0, 1, 0, 1, 0)
def twoMinutesPastMidnight = new Date(100, 0, 1, 0, 2, 0)
assert (midnight + 1.minute) == oneMinutePastMidnight
assert (midnight + 2.minutes) == twoMinutesPastMidnight
assert (twoMinutesPastMidnight - 60.seconds) == oneMinutePastMidnight
//assert (twoMinutesPastMidnight - 1.minute) == oneMinutePastMidnight //todo: this should work but fails
assert (twoMinutesPastMidnight - 120.seconds) == midnight
//assert (twoMinutesPastMidnight - 2.minutes) == midnight //todo: this should work but fails
}
}
void testDurationArithmeticOnHours() {
use(TimeCategory) {
def midnight = new Date(100, 0, 1, 0, 0, 0)
def oneAM = new Date(100, 0, 1, 1, 0, 0)
def twoAM = new Date(100, 0, 1, 2, 0, 0)
assert (midnight + 1.hour) == oneAM
assert (midnight + 2.hours) == twoAM
assert (twoAM - 3600.seconds) == oneAM
//assert (twoAM - 1.hour) == oneAM //todo: this should work but fails
assert (twoAM - 7200.seconds) == midnight
//assert (twoAM - 2.hours) == midnight //todo: this should work but fails
}
}
Should be fixed in HEAD - thanks for spotting this.