JDK-6211541 : TimeZone class doesn't support all Time Zones
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-12-22
  • Updated: 2010-04-02
  • Resolved: 2005-01-05
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
TimeZone class in Java doesn't always match other time zone libraries, and I looked around and there are a few missing timezones, where Java only supports the abbreviation and not the actual time zone ID.

Such as EST5 and MST7 are not supported in Java, but java has a less accurate and abbreviated version in the form of EST and MST respectively.

Then you also have UTC but not UTC0 (to stay consistent it should also be included)

In the Java 1.5.0 javadocs there is a paragraph regarding abbreviations, that java shouldn't support such abbreviations (although it wasn't directed at the aforementioned abbreviations):

Three-letter time zone IDs
For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run my program below

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should list EST5 and MST7 (and UTC0)
ACTUAL -
It only lists EST and MST (and UTC)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
The error is in the output

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.TimeZone;

public class TimeZoneTest{

   public static void main(String[] args){
      
      //Get all the available time zones
      args = TimeZone.getAvailableIDs();
      
      //Print all time zones accepted
      for(int i=0; i<args.length; i++)
         System.out.println(args[i]);
      
      System.out.println("----------------");
      
      //Print only selected time zones
      for(int i=0; i<args.length; i++){
         if(args[i].indexOf("MST") != -1)
            System.out.println(args[i]);
         if(args[i].indexOf("UTC") != -1)
            System.out.println(args[i]);
         if(args[i].indexOf("EST") != -1)
            System.out.println(args[i]);
      }
   }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I have to catch the time zone ID sent by other libraries and/or entered in by the user and append the 5 or 7 (or 0) where I need to. This would be avoided if it accepted the readl time zone id rather than just the abbreviations (in the instances I have mentioned)
###@###.### 2004-12-22 01:01:32 GMT

Comments
EVALUATION The Java runtime supports the Olson public zone info data in which EST5, MST7, etc. are not time zone IDs. Those are valid TZ values under the POSIX specification, though. Closing this bug report as a duplicate of 4263805. ###@###.### 2005-1-05 07:19:59 GMT
05-01-2005