[ 
https://issues.apache.org/jira/browse/GROOVY-8368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16225702#comment-16225702
 ] 

Brian Koehmstedt commented on GROOVY-8368:
------------------------------------------

I should add I just showed this issue to my boss and he is already trying to 
explain to me why he doesn't think this is an actual bug, but I'm not quite 
following the explanation.  From my very-programmer-centric mindset, "assert a 
+ b + c == a + c + b" should always succeed no matter what data type b and c 
are.  But at any rate, if someone else other than my boss can explain why "this 
isn't a bug" for my "programmer-centric" mindset, I'll be happy to close it as 
not-a-bug.


> date arithmetic bug using TimeCategory intervals
> ------------------------------------------------
>
>                 Key: GROOVY-8368
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8368
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.6.0-alpha-1
>         Environment: Ubuntu 16.04, Groovy 2.6.0-alpha-1, OpenJDK 1.8.0_131
>            Reporter: Brian Koehmstedt
>            Priority: Minor
>         Attachments: intervalBug.groovy
>
>
> There's what I think to be a date arithmetic bug using TimeCategory intervals 
> and it appears to show itself only the 30th of any given month.  I noticed 
> this because our automatic builds fail towards the end of the month and this 
> has been going on for a long time.  I decided to hunt this down today (Oct 
> 30) as the build failed today and I had time to track it down.  I was able to 
> produce a small script to reproduce it, as shown below.  I tested with latest 
> 2.6.0 alpha1 as well as 2.4.10 (what we're actually using).  Both show the 
> bug.
> I don't have an opinion on how "1.month" is interpreted in Groovy.  That's 
> not what this submission is about.  The bug I am reporting here is that the 
> following two expressions should always evaluate to the same value and it 
> appears they don't on the 30th of the month:
> {code}
> Date now = new Date().clearTime()
> // fails on the 30th of the month (at least, for Oct 30 2017)
> assert now + 1.month + 1.day == now + 1.day + 1.month
> {code}
> {code}
> // START of intervalBug.groovy
> import groovy.time.TimeCategory
> Date now = new Date().clearTime()
> println "current date = $now"
> use(TimeCategory) {
>   println "now+1day+1month = ${now + 1.day + 1.month}"
>   println "now+1month+1day = ${now + 1.month + 1.day}"
> }
> // END of intervalBug.groovy
> {code}
> {noformat}
> # also tested with groovy-2.4.10 with same buggy result
> $ groovy -v
> Groovy Version: 2.6.0-alpha-1 JVM: 1.8.0_131 Vendor: Oracle Corporation OS: 
> Linux
> # 29th of month is OK: same result produced
> $ sudo date -s "29 OCT 2017 13:00:00"; groovy intervalBug.groovy
> Sun Oct 29 13:00:00 PDT 2017
> current date = Sun Oct 29 00:00:00 PDT 2017
> now+1day+1month = Thu Nov 30 00:00:00 PST 2017
> now+1month+1day = Thu Nov 30 00:00:00 PST 2017
> # 30th of month is BUGGY: different result produced
> $ sudo date -s "30 OCT 2017 13:00:00"; groovy intervalBug.groovy
> Mon Oct 30 13:00:00 PDT 2017
> current date = Mon Oct 30 00:00:00 PDT 2017
> now+1day+1month = Thu Nov 30 00:00:00 PST 2017
> now+1month+1day = Fri Dec 01 00:00:00 PST 2017
> # 31st of month is OK
> $ sudo date -s "31 OCT 2017 13:00:00"; groovy intervalBug.groovy
> [sudo] password for bkoehmstedt: 
> Tue Oct 31 13:00:00 PDT 2017
> current date = Tue Oct 31 00:00:00 PDT 2017
> now+1day+1month = Fri Dec 01 00:00:00 PST 2017
> now+1month+1day = Fri Dec 01 00:00:00 PST 2017
> # 1st of month is OK
> $ sudo date -s "01 NOV 2017 13:00:00"; groovy intervalBug.groovy
> [sudo] password for bkoehmstedt: 
> Wed Nov  1 13:00:00 PDT 2017
> current date = Wed Nov 01 00:00:00 PDT 2017
> now+1day+1month = Sat Dec 02 00:00:00 PST 2017
> now+1month+1day = Sat Dec 02 00:00:00 PST 2017
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to