|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
TimeCategory subtraction not working?Hi,
I'm working on unit tests for TimeCategory and I'm seeing strange behavior in Minute based subtraction. 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. Here is the code (note the lines marked "fails!"): use(TimeCategory) { //use January 1 to avoid leap years and daylight savings time issues 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 (twoMinutesPastMidnight - 60.seconds) == oneMinutePastMidnight //works! assert (twoMinutesPastMidnight - 1.minute) == oneMinutePastMidnight //fails!! assert (twoMinutesPastMidnight - 120.seconds) == midnight //works! assert (twoMinutesPastMidnight - 2.minutes) == midnight //fails! } My codebase is from Oct. 16th, 2007. Thanks in advance. --
Hamlet D'Arcy |
|
|
Re: TimeCategory subtraction not working?Looks like a bug: HamletDRC wrote: > Hi, > I'm working on unit tests for TimeCategory and I'm seeing strange behavior > in Minute based subtraction. > > 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. > > Here is the code (not the lines marked "fails!"): > > use(TimeCategory) { > //use January 1 to avoid leap years and daylight savings time issues > 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 (twoMinutesPastMidnight - 60.seconds) == oneMinutePastMidnight > //works! > assert (twoMinutesPastMidnight - 1.minute) == oneMinutePastMidnight > //fails!! > > assert (twoMinutesPastMidnight - 120.seconds) == midnight //works! > assert (twoMinutesPastMidnight - 2.minutes) == midnight //fails! > } > > My codebase is from Oct. 16th, 2007. > > Thanks in advance. > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: TimeCategory subtraction not working?Also,
When performing date subtraction using: public static TimeDuration minus(final Date lhs, final Date rhs) The returned object is a TimeDuration, but the constructor used to create it is the one without years and months set... so calling getMonth or getYear on any result of date subtraction always returns zero. Is this a bug or expected behavior? THanks, Hamlet P.S. Do I create the bug myself? (sorry, I'm new)
--
Hamlet D'Arcy |
|
|
Re: TimeCategory subtraction not working?Created issue 2218 to address the original problem.
http://jira.codehaus.org/browse/GROOVY-2218
--
Hamlet D'Arcy |
|
|
Re: TimeCategory subtraction not working?HamletDRC wrote:
> Created issue 2218 to address the original problem. > > http://jira.codehaus.org/browse/GROOVY-2218 Fixed and your tests applied. Just the daylight saving stuff is now not covered in TimeCategory though we still have a bit to do within the groovy.time helper classes. Thanks, Paul. > HamletDRC wrote: >> Also, >> >> When performing date subtraction using: >> >> public static TimeDuration minus(final Date lhs, final Date rhs) >> >> The returned object is a TimeDuration, but the constructor used to create >> it is the one without years and months set... so calling getMonth or >> getYear on any result of date subtraction always returns zero. >> >> Is this a bug or expected behavior? >> >> THanks, Hamlet >> >> P.S. Do I create the bug myself? (sorry, I'm new) >> >> >> >> >> Paul King wrote: >>> >>> Looks like a bug: >>> >>> HamletDRC wrote: >>>> Hi, >>>> I'm working on unit tests for TimeCategory and I'm seeing strange >>>> behavior >>>> in Minute based subtraction. >>>> >>>> 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. >>>> >>>> Here is the code (not the lines marked "fails!"): >>>> >>>> use(TimeCategory) { >>>> //use January 1 to avoid leap years and daylight savings time issues >>>> 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 (twoMinutesPastMidnight - 60.seconds) == oneMinutePastMidnight >>>> //works! >>>> assert (twoMinutesPastMidnight - 1.minute) == oneMinutePastMidnight >>>> //fails!! >>>> >>>> assert (twoMinutesPastMidnight - 120.seconds) == midnight //works! >>>> assert (twoMinutesPastMidnight - 2.minutes) == midnight //fails! >>>> } >>>> >>>> My codebase is from Oct. 16th, 2007. >>>> >>>> Thanks in advance. >>>> >>> >> > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |