Groovy
  1. Groovy
  2. GROOVY-3332

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

    Details

    • Type: Improvement Improvement
    • Status: 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

      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

          Alexander Veit created issue -
          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?
          Brad Long made changes -
          Field Original Value New Value
          Attachment Groovy3332Bug.groovy [ 50301 ]
          Attachment groovy-3332.patch [ 50300 ]
          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
          Pascal Schumacher made changes -
          Issue Type Bug [ 1 ] Improvement [ 4 ]
          Assignee Pascal Schumacher [ pschumacher ]
          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.
          Pascal Schumacher made changes -
          Resolution Fixed [ 1 ]
          Fix Version/s 2.2.0-beta-1 [ 19074 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Pascal Schumacher made changes -
          Link This issue is duplicated by GROOVY-6083 [ GROOVY-6083 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12732328 ] Default workflow, editable Closed status [ 12744139 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12970153 ] Default workflow, editable Closed status [ 12977920 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          1463d 21h 15m 1 Pascal Schumacher 05/Feb/13 12:42
          Resolved Resolved Closed Closed
          154d 16h 1 Paul King 10/Jul/13 05:42

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development