Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4326867

GregorianCalendar.add does extra setTimeInMillis call for field UOM < MONTH.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs



      Name: stC104175 Date: 03/31/2000


      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      The following code exists at the bottom of the GregorianCalendar.add method. In
      spite of the comment, the extra call to setTimeInMillis is done every time,
      slowing down date math. The last if statement should compare dst (rather than
      delta) to zero.

      This bug goes back to at least version 1.2.

      // Save the current DST state.
      long dst = 0;
      if (adjustDST) dst = internalGet(DST_OFFSET);

      setTimeInMillis(time + delta); // Automatically computes
      fields if necessary

      if (adjustDST) {
      // Now do the DST adjustment alluded to above.
      // Only call setTimeInMillis if necessary,
      because it's an expensive call.
      dst -= internalGet(DST_OFFSET);
      if (delta != 0) setTimeInMillis(time + dst);
      }
      (Review ID: 103093)
      ======================================================================

            okutsu Masayoshi Okutsu
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: