2007 U.S Daylight Saving Time Remedies for Java/iX 1.3.0

»  Home

» Software
» Papers & Training
» Java
»  Supported JDKs
» OpenSource class libs
» Documentation
» Support
» FAQ
» DST


Support for Java/iX on MPE/iX has ended on 31 December 2006. For that reason, HP will be unable to provide an updated Java Runtime Environment (JRE) for Java/iX 1.3.0 to address the changes for Daylight Saving Time in 2007.

Applications written in Java running on MPE/iX will be affected by the Daylight Saving Time changes which take affect at 2 am on 11 March 2007.

This page, however, details two possible remedies for the Daylight Saving Time change for users of Java/iX 1.3.0 on MPE/iX releases.


Note: The remedies described below have been tested using Java/iX 1.3.0. They may also work with earlier releases of Java/iX.
Regardless of your release of Java/iX you should thoroughly test these or any remedies before electing to include them in any mission critical Java/iX application.

I. Manually Adjust The GMT Offset When Java Applications are Run

You can manually alter the timezone GMT (Greenwich Mean Time) adjustment used by Java on the command line when a Java application is run. You would do this by using the "-D" option to set the system property "user.timezone" with the correct GMT offset in hours, i.e.

java -Duser.timezone=GMT[+/-offset hours] java.class

For example, you are in the Pacific Timezone which has an 8 hour GMT offset in standard time. After the start of Daylight Saving Time on 11 March the GMT offset will be 7 hours. Java's built in timezone adjustment will not take affect because it is set to make DST adjustments under the pre-2007 rules which would have DST begin at 2 am on 1 April 2007. You can force Java to use a 7 hour adjustment as follows:

Shell/iX> java -Duser.timezone=GMT-7 java_application

To further clarify the effect of this option, here is a simple Java program that displays the current date and time:
import java.util.*;
public class DispDate {
    public static void main(String[] args) {
      Date foo = new Date();
      System.out.println("Date = " + foo.toString());
    }
}     
Running this program produces:
Shell/iX> java DispDate
Date = Thu Feb 15 11:16:19 PST 2007     
Running the program and supplying an override GMT offset produces:
Shell/iX> java -Duser.timezone=GMT-7 DispDate
Date = Thu Feb 15 12:17:48 GMT-07:00 2007     
The timestamp displayed is now one hour earlier but notice that the default format for this timestamp now also includes the "GMT-07:00" string indicating the adjustment.

Please consider the effect this change in timestamp format will have on your applications and on any applications which rely on timestamp output from a Java/iX application.


Note: You will need to remember to remove the override GMT offset at the resumption of Standard time on the first Sunday in November.

II. Create a New Custom Timezone Definition


Note: This is a very basic example of how to create and use a custom timezone. The actual implementation of a custom timezone is far more involved. For example, you will need to create new custom timezones for each timezone in the U.S. and elsewhere affected by the new Daylight Saving Time rules. And you will need to design the change to take into account the ruleset that must be used to translate GMT to local time based on the year the timestamp represents and the location the adjustment must be made for.

For example, you would not use the 2007 rules to translate GMT to local time for dates in prior years. And you would not use a custom timezone for Pacific Time for users accessing your application from New York City!
Also Note: Please do not consider this remedy unless you are familiar with Java programming and able to make changes to your application source files. If you are not familiar with Java you may want to consider engaging the services of a trained Java consultant.
Following is an example showing how to define a custom timezone using the SimpleTimeZone class. This example verifies the custom timezone by creating timestamps before and after the start and end of daylight saving time by the 2007 rules.
import java.text.*;
import java.util.*;

public class DST2007
{

    // A documentation convenience since times in Java are all
    // represented milliseconds.

    private static int one_hour_in_ms = 60 * 60 * 1000;

    public static void main(String[] argv)
    throws Exception
    {

    // Get the current time zone as a basis for the new one.

    DateFormat df = DateFormat.getInstance();
    TimeZone tz = df.getTimeZone();

    // Create a new timezone using the U.S. definition that
    // daylight saving time begins the 2nd Sunday of March and
    // ends on the first Sunday in November. This change goes
    // into effect in 2007.

    SimpleTimeZone tz_NEW_Rules = new SimpleTimeZone (

        tz.getRawOffset(),     // Use the current offset from GMT
        tz.getID(),            // Use the current ID
        Calendar.MARCH,        // Now starts in March
        2,                     // on the 2nd
        Calendar.SUNDAY,       // Sunday at
        (one_hour_in_ms * 2),  // 2am
        Calendar.NOVEMBER,     // Ends in November
        1,                     // on the 1st
        Calendar.SUNDAY,       // Sunday
        (one_hour_in_ms * 2),  // 2am
        (one_hour_in_ms * 1)   // 1 hour adjustment
    );

    // Set a date format using the new 2007 time zone.
    SimpleDateFormat fmt2007 =
        new SimpleDateFormat("MMM dd yyyy HH:mm zzz");
    fmt2007.setTimeZone(tz_NEW_Rules);

    // Do the same for the current time zone.
    SimpleDateFormat fmtCURR =
        new SimpleDateFormat("MMM dd yyyy HH:mm zzz");
    fmtCURR.setTimeZone(TimeZone.getDefault());

    // According to the new daylight saving time rules in the U.S.
    // DST will begin Sunday, March 11 2007 at 2am. It will end on
    // Sunday, November 4, 2007 at 2am.

    // Create a couple of sample dates that by the current rules
    // will use standard time to see if the switch to daylight saving
    // time occurs correctly.

    // March 10, 2007, 12:00:00
    Date d1 = ( new GregorianCalendar ( 2007,
                                        Calendar.MARCH,
                                        10,
                                        12,
                                        00,
                                        00) ).getTime();

    // March 11, 2007, 12:00:00
    Date d2 = ( new GregorianCalendar ( 2007,
                                        Calendar.MARCH,
                                        11,
                                        12,
                                        00,
                                        00) ).getTime();

    System.out.println(" ");
    System.out.println(fmtCURR.format(d1) + 
       " with 2007 rules results in -> " +
                       fmt2007.format(d1));
    System.out.println(fmtCURR.format(d2) + 
       " with 2007 rules results in -> " +
                       fmt2007.format(d2));

    // Create two new dates to make sure DST ends correctly.

    // November 3, 2007, 12:00:00
    Date d3 = ( new GregorianCalendar ( 2007,
                                        Calendar.NOVEMBER,
                                        3,
                                        12,
                                        00,
                                        00) ).getTime();

    // November 4, 2007, 12:00:00
    Date d4 = ( new GregorianCalendar ( 2007,
                                        Calendar.NOVEMBER,
                                        4,
                                        12,
                                        00,
                                        00) ).getTime();

    System.out.println(fmtCURR.format(d3) + 
       " with 2007 rules results in -> " +
                       fmt2007.format(d3));
    System.out.println(fmtCURR.format(d4) + 
       " with 2007 rules results in -> " +
                       fmt2007.format(d4));
    }
}     
Running this program produces the following output:
Shell/iX> java DST2007

Mar 10 2007 12:00 PST with 2007 rules results in -> Mar 10 2007 12:00 PST
Mar 11 2007 12:00 PST with 2007 rules results in -> Mar 11 2007 13:00 PDT
Nov 03 2007 12:00 PST with 2007 rules results in -> Nov 03 2007 13:00 PDT
Nov 04 2007 12:00 PST with 2007 rules results in -> Nov 04 2007 12:00 PST
      

Top    Jazz java    Hosted by 3kRanger.com    email 3kRanger    Updated