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

Los Pejos commented on GROOVY-7964:
-----------------------------------

On another Windows 10 machine it gives the same result (invalid TimeCategory 
result).
My timezone is:
Current Timezone: 
sun.util.calendar.ZoneInfo[id="Europe/Helsinki",offset=7200000,dstSavings=3600000,useDaylight=true,transitions=118,lastRule=java.util.SimpleTimeZone[id=Europe/Helsinki,offset=7200000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
I updated attached sample file.

> TimeCategory incorrectly counts days difference between two dates
> -----------------------------------------------------------------
>
>                 Key: GROOVY-7964
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7964
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>         Environment: Windows 10 x86_64, Oracle Java 1.8.0.102 x86_64 
>            Reporter: Los Pejos
>              Labels: timecategory
>         Attachments: DatesDiff.groovy
>
>
> TimeCategory incorrectly counts days difference between two dates.
> Exhibit (Groovy code):
> {code}
> #!/usr/bin/env groovy
> @Grab(group='joda-time', module='joda-time', version='2.9.4+')
> import java.io.BufferedReader
> import java.io.IOException
> import java.io.InputStreamReader
> import java.time.LocalDate
> import java.time.format.DateTimeFormatter
> import java.time.temporal.ChronoUnit
> import groovy.time.TimeCategory
> String date1 = '2016-03-22'
> String date2 = '2016-03-29'
> String fmt = 'yyyy-MM-dd'
> // Java 8 ChronoUnit:
> DateTimeFormatter formatter = DateTimeFormatter.ofPattern(fmt)
> //LocalDate firstDate = LocalDate.parse(date1, formatter)
> //LocalDate secondDate = LocalDate.parse(date2, formatter)
> long days = ChronoUnit.DAYS.between(
>       LocalDate.parse(date1, formatter), 
>       LocalDate.parse(date2, formatter)
> )
> println "Java 8 ChronoUnit: Dates between $date1 and $date2 : $days"
> // Groovy TimeCategory/Date:
> use (TimeCategory) {
>       def d = (Date.parse(fmt, date2) - Date.parse(fmt, date1)).days
>       println "Groovy TimeCategory/Date: Dates between $date1 and $date2 : $d"
> }
> // Joda Time:
> // LocalDate fromDateFields(Date date)
> // Date.parse('yyyy-MM-dd', dlf.@dldpf.toString())
> days = org.joda.time.Days.daysBetween(
>       org.joda.time.LocalDate.fromDateFields(Date.parse(fmt,date1)), 
>       org.joda.time.LocalDate.fromDateFields(Date.parse(fmt,date2))
> ).getDays()
> println "Joda Time: Dates between $date1 and $date2 : $days"
> {code}
> Current Output:
> {noformat}
> $ groovy DatesDiff.groovy
> Java 8 ChronoUnit: Dates between 2016-03-22 and 2016-03-29 : 7
> Groovy TimeCategory/Date: Dates between 2016-03-22 and 2016-03-29 : 6
> Joda Time: Dates between 2016-03-22 and 2016-03-29 : 7
> {noformat}
> Expected Output:
> {noformat}
> $ groovy DatesDiff.groovy
> Java 8 ChronoUnit: Dates between 2016-03-22 and 2016-03-29 : 7
> Groovy TimeCategory/Date: Dates between 2016-03-22 and 2016-03-29 : 7
> Joda Time: Dates between 2016-03-22 and 2016-03-29 : 7
> {noformat}
> Resume: notice the difference in "Groovy TimeCategory/Date" line.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to