groovy
  1. groovy
  2. GROOVY-4100

clearTime() fails for times in the afternoon

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.1
    • Fix Version/s: 1.7.2, 1.6.9, 1.8-beta-1
    • Component/s: groovy-jdk
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Calendar.clearTime() fails if the time part of the date is in the afternoon.

      The gdk seems to be doing:

      self.clear(Calendar.HOUR_OF_DAY);
      self.clear(Calendar.HOUR);
      

      I think that second line is unnecessary and breaking things.

      Some test code:

      // clearTime works for times in the morning
      def morning = GregorianCalendar.getInstance()
      morning.set(Calendar.AM_PM, Calendar.AM)
      morning.clearTime()
      assert morning.get(Calendar.HOUR_OF_DAY) == 0
      
      // clearTime fails for times in the afternoon
      def afternoon = GregorianCalendar.getInstance()
      afternoon.set(Calendar.AM_PM, Calendar.PM)
      afternoon.clearTime()
      assert afternoon.get(Calendar.HOUR_OF_DAY) == 0  // fails in Groovy 1.7.1
      

        Activity

        Hide
        Paul King added a comment -

        The javadoc says to use set(Calendar.HOUR_OF_DAY, 0) for that case. Seems to work in my testing. Changed.

        Show
        Paul King added a comment - The javadoc says to use set(Calendar.HOUR_OF_DAY, 0) for that case. Seems to work in my testing. Changed.
        Hide
        Kon Soulianidis added a comment -

        Can you please port this fix to the 1.6.x branch too?
        Grails 1.2.2 recently updated to Groovy 1.6.8 which contains this feature (and now defect) as well. I wouldn't expect Grails to be using 1.7 as quickly as they could a 1.6 update

        Show
        Kon Soulianidis added a comment - Can you please port this fix to the 1.6.x branch too? Grails 1.2.2 recently updated to Groovy 1.6.8 which contains this feature (and now defect) as well. I wouldn't expect Grails to be using 1.7 as quickly as they could a 1.6 update
        Hide
        Paul King added a comment -

        Merged onto 1_6_X branch

        Show
        Paul King added a comment - Merged onto 1_6_X branch

          People

          • Assignee:
            Paul King
            Reporter:
            Glen Conboy
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: