groovy
  1. groovy
  2. GROOVY-3332

The groovy.time.*Duration classes make use of java.sql.Date

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-rc-2
    • Fix Version/s: 2.2.0-beta-1
    • Component/s: groovy-jdk
    • Labels:
      None
    • Number of attachments :
      2

      Description

      The groovy.time.*Duration classes make use of java.sql.Date, but there seems to be no justification for doing so.

      java.sql.Date is basically the same as java.util.Date except for the toString() formatting. So the second assert fails while the first assert succeeds:

      use (org.codehaus.groovy.runtime.TimeCategory) {
      
       Date dt1 = 0.days.from.now
       Date dt2 = new Date(0.days.from.now.time)
      
       assert dt1 == dt2
       assert dt1.toString() == dt2.toString() 
      }
      
      1. groovy-3332.patch
        1 kB
        Brad Long
      2. Groovy3332Bug.groovy
        0.4 kB
        Brad Long

        Issue Links

          Activity

          Hide
          Paul King added a comment -

          I suspect that all references to groovy.sql.Date should be replaced with groovy.util.Date

          Show
          Paul King added a comment - I suspect that all references to groovy.sql.Date should be replaced with groovy.util.Date
          Hide
          Brad Long added a comment -

          Patch and test attached. Replaced occurrences of java.sql.Date with Date. But surely there was a reason java.sql.Date was being used in the first place?

          Show
          Brad Long added a comment - Patch and test attached. Replaced occurrences of java.sql.Date with Date. But surely there was a reason java.sql.Date was being used in the first place?
          Hide
          Alexander Veit added a comment -

          Probably, but the reason is somewhat obscure. Maybe the following sentence from java.sql.Date's documentation has something to do with it.

          To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

          Show
          Alexander Veit added a comment - Probably, but the reason is somewhat obscure. Maybe the following sentence from java.sql.Date's documentation has something to do with it. To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
          Hide
          Pascal Schumacher added a comment -

          I created a pull request out of Brads patch:

          https://github.com/groovy/groovy-core/pull/135

          Show
          Pascal Schumacher added a comment - I created a pull request out of Brads patch: https://github.com/groovy/groovy-core/pull/135
          Hide
          Pascal Schumacher added a comment -

          Patch applied. Thanks for the patch and for the anaylsis.

          Show
          Pascal Schumacher added a comment - Patch applied. Thanks for the patch and for the anaylsis.

            People

            • Assignee:
              Pascal Schumacher
              Reporter:
              Alexander Veit
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: