Issue Details (XML | Word | Printable)

Key: GROOVY-2218
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Hamlet D'Arcy
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

TimeCategory Date subtraction does not always work for hours and minutes

Created: 16/Oct/07 10:42 PM   Updated: 22/Nov/07 05:20 AM
Component/s: None
Affects Version/s: 1.1-rc-1
Fix Version/s: 1.1-rc-2

Time Tracking:
Not Specified

Environment: Windows XP. java version "1.5.0_08". Ant 1.7

Testcase included: yes


 Description  « Hide
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 }
}



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King added a comment - 16/Oct/07 11:38 PM
Should be fixed in HEAD - thanks for spotting this.