JDK-4813743 : Calendar.set() changes the daylight savings time marker
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2003-02-05
  • Updated: 2003-02-06
  • Resolved: 2003-02-06
Related Reports
Duplicate :  
Description

Name: jl125535			Date: 02/05/2003


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

FULL OPERATING SYSTEM VERSION :
Linux 2.4.9-21enterprise

ADDITIONAL OPERATING SYSTEMS :
Windows 2k
ALL because it is a problem in Calendar.java and its
subclasses

A DESCRIPTION OF THE PROBLEM :
Calling of the set method in Calendar causes the calendar to
shift from PDT back to PST.  See test in Source Code
section.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code in source code section.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected results:
date  Sun Oct 27 01:00:00 PST 2002
date  Sun Oct 27 01:59:59 PDT 2002
date  Sun Oct 27 01:59:59 PDT 2002

Actual Results:
date  Sun Oct 27 01:00:00 PST 2002
date  Sun Oct 27 01:59:59 PDT 2002
date  Sun Oct 27 01:00:59 PST 2002


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.math.*;
import java.net.*;
import java.text.*;
import java.util.*;

public class CalendarBug {
    public static void main(String args[]){
        long DELTA = 1111l;

        Calendar cal = Calendar.getInstance();
        cal.set(2002, Calendar.OCTOBER, 27, 1, 0, 0);
        Date date = cal.getTime();
        System.out.println("date  " + date);

        long delta = date.getTime() - DELTA;

        cal.setTimeInMillis(delta);
        date = cal.getTime();
        System.out.println("date  " + date);

        // Anyone of the following set() or clear() calls will cause
        // the date to switch from PDT to PST

        cal.set( Calendar.MINUTE, 0 );
//          cal.set( Calendar.SECOND, 0 );
//          cal.set( Calendar.MILLISECOND, 0 );
//          cal.clear( Calendar.MINUTE );
//          cal.clear( Calendar.SECOND );
//          cal.clear( Calendar.MILLISECOND );

        date = cal.getTime();
        System.out.println("date  " + date);
    }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Use a set of something like

cal.set(Calendar.MINUTE, -1 * cal.get(Calendar.MINUTE));
(Review ID: 166646) 
======================================================================

Comments
EVALUATION Currently, there's no way to specify how to disambiguate standard time and daylight saving time and each method calculates time differently. Closing this as a duplicate of 4312621. ###@###.### 2003-02-06
06-02-2003

WORK AROUND Changing cal.set( Calendar.MINUTE, 0 ); to cal.add(Calendar.MINUTE, -cal.get(cal.MINUTE)); produces: date Sun Oct 27 01:00:00 PST 2002 date Sun Oct 27 01:59:59 PDT 2002 date Sun Oct 27 01:00:59 PDT 2002 ###@###.### 2003-02-06
06-02-2003