Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-498

GregorianCalendar clone problem

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • None
    • Classlib
    • None

    Description

      The following test code breaks on Harmony. Setting milliseconds to zero alters the day of the month. Output on RI is:

      today time = Tue May 23 14:06:51 BST 2006
      yesterday time = Mon May 22 14:06:51 BST 2006
      day of month before resetting milliseconds = 23
      day of month after resetting milliseconds = 23
      time before resetting seconds = Tue May 23 14:06:51 BST 2006
      time after resetting seconds = Tue May 23 14:06:00 BST 2006

      Output on Harmony is:

      today time = Tue May 23 13:59:39 BST 2006
      yesterday time = Mon May 22 13:59:39 BST 2006
      day of month before resetting milliseconds = 23
      day of month after resetting milliseconds = 22
      time before resetting seconds = Tue May 23 13:59:39 BST 2006
      time after resetting seconds = Mon May 22 13:59:00 BST 2006

      I suspect it might have something to do with the cachedFields?

      import java.util.TimeZone;
      import java.util.Calendar;

      public class Test2 {

      public static void main(String[] args)

      { Calendar today = Calendar.getInstance(); System.err.println("today time = "+today.getTime()); Calendar yesterday = (Calendar)today.clone(); // copy not deep enough? yesterday.add(Calendar.DATE, -1); System.err.println("yesterday time = "+yesterday.getTime()); Calendar broken = (Calendar)today.clone(); System.err.println("day of month before resetting milliseconds = "+ broken.get(Calendar.DAY_OF_MONTH)); broken.set(Calendar.MILLISECOND, 0); System.err.println("day of month after resetting milliseconds = "+ broken.get(Calendar.DAY_OF_MONTH)); System.err.println("time before resetting seconds = "+broken.getTime()); broken.set(Calendar.SECOND, 0); System.err.println("time after resetting seconds = "+broken.getTime()); }

      }

      Attachments

        Activity

          People

            smm Stepan Mishura
            hindessm Mark Hindess
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: