United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4813746 The java.util.TimeZone ID "Etc/GMT+offset" Gives Incorrect TimeZone
JDK-4813746 : The java.util.TimeZone ID "Etc/GMT+offset" Gives Incorrect TimeZone

Details
Type:
Bug
Submit Date:
2003-02-05
Status:
Closed
Updated Date:
2003-02-06
Project Name:
JDK
Resolved Date:
2003-02-06
Component:
core-libs
OS:
windows_2000
Sub-Component:
java.util:i18n
CPU:
x86
Priority:
P4
Resolution:
Not an Issue
Affected Versions:
1.4.1
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description

Name: nt126004			Date: 02/05/2003


FULL PRODUCT VERSION :
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 :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
With the lines below the ID "Etc/GMT-8" is treated as
GMT+8:00, and ID "Etc/GMT+8" is treated as GMT-8:00.   This
seems erroneous or at least misleading.

import java.util.*;

public final class EtcTimeZone{
public static void main(String[] args) throws
java.lang.Exception{
String[] ids =
java.util.TimeZone.getAvailableIDs(-8*60*60*1000);
for(int i=0;i<ids.length;i++){
	System.out.println(ids[i]);
}
// In the result there is the ID "Etc/GMT+8"
 ids = java.util.TimeZone.getAvailableIDs(8*60*60*1000);
for(int i=0;i<ids.length;i++){
	System.out.println(ids[i]);
}
// In the result there is the ID "Etc/GMT-8"

System.out.println();
java.util.TimeZone zone =
java.util.TimeZone.getTimeZone("Etc/GMT-8");
System.out.println(zone.getDisplayName());//result is GMT+8


zone = java.util.TimeZone.getTimeZone("Etc/GMT+8");
System.out.println(zone.getDisplayName());//result is GMT-8

}
}



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Straightforward and seems there is no need for steps of
reproducing.


EXPECTED VERSUS ACTUAL BEHAVIOR :
"Etc/GMT-8"  ->  GMT-8:00
"Etc/GMT+8" ->  GMT+8:00

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
//The following is the reproduction of the code give above:

import java.util.*;

public final class EtcTimeZone{
public static void main(String[] args) throws java.lang.Exception{
String[] ids = java.util.TimeZone.getAvailableIDs(-8*60*60*1000);
for(int i=0;i<ids.length;i++){
	System.out.println(ids[i]);
}
// In the result there is the ID "Etc/GMT+8"
 ids = java.util.TimeZone.getAvailableIDs(8*60*60*1000);
for(int i=0;i<ids.length;i++){
	System.out.println(ids[i]);
}
// In the result there is the ID "Etc/GMT-8"

System.out.println();
System.out.println("getting TimeZone for \"Etc/GMT-8\"");
java.util.TimeZone zone = java.util.TimeZone.getTimeZone("Etc/GMT-8");
System.out.println(zone.getDisplayName());//result is GMT+8

System.out.println("getting TimeZone for \"Etc/GMT+8\"");
zone = java.util.TimeZone.getTimeZone("Etc/GMT+8");
System.out.println(zone.getDisplayName());//result is GMT-8

}
}


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

CUSTOMER WORKAROUND :
Actually I do not use these ID's.
(Review ID: 180806) 
======================================================================

                                    

Comments
EVALUATION

Java follows the definitions by the Olson public source. The definitions of Etc/GMT+-* are as follows:

# @(#)etcetera	7.11

# These entries are mostly present for historical reasons, so that
# people in areas not otherwise covered by the tz files could "zic -l"
# to a time zone that was right for their area.  These days, the
# tz files cover almost all the inhabited world, so there's little
# need now for the entries that are not on UTC.

Zone	Etc/GMT		0	-	GMT
Zone	Etc/UTC		0	-	UTC
Zone	Etc/UCT		0	-	UCT

# The following link uses older naming conventions,
# but it belongs here, not in the file `backward',
# as functions like gmtime load the "GMT" file to handle leap seconds properly.
# We want this to work even on installations that omit the other older names.
Link	Etc/GMT				GMT

Link	Etc/UTC				Etc/Universal
Link	Etc/UTC				Etc/Zulu

Link	Etc/GMT				Etc/Greenwich
Link	Etc/GMT				Etc/GMT-0
Link	Etc/GMT				Etc/GMT+0
Link	Etc/GMT				Etc/GMT0

# We use POSIX-style signs in the Zone names and the output abbreviations,
# even though this is the opposite of what many people expect.
# POSIX has positive signs west of Greenwich, but many people expect
# positive signs east of Greenwich.  For example, TZ='Etc/GMT+4' uses
# the abbreviation "GMT+4" and corresponds to 4 hours behind UTC
# (i.e. west of Greenwich) even though many people would expect it to
# mean 4 hours ahead of UTC (i.e. east of Greenwich).
#
# In the draft 5 of POSIX 1003.1-200x, the angle bracket notation
# (which is not yet supported by the tz code) allows for
# TZ='<GMT-4>+4'; if you want time zone abbreviations conforming to
# ISO 8601 you can use TZ='<-0400>+4'.  Thus the commonly-expected
# offset is kept within the angle bracket (and is used for display)
# while the POSIX sign is kept outside the angle bracket (and is used
# for calculation).
#
# Do not use a TZ setting like TZ='GMT+4', which is four hours behind
# GMT but uses the completely misleading abbreviation "GMT".

# Earlier incarnations of this package were not POSIX-compliant,
# and had lines such as
#		Zone	GMT-12		-12	-	GMT-1200
# We did not want things to change quietly if someone accustomed to the old
# way does a
#		zic -l GMT-12
# so we moved the names into the Etc subdirectory.

Zone	Etc/GMT-14	14	-	GMT-14	# 14 hours ahead of GMT
Zone	Etc/GMT-13	13	-	GMT-13
Zone	Etc/GMT-12	12	-	GMT-12
Zone	Etc/GMT-11	11	-	GMT-11
Zone	Etc/GMT-10	10	-	GMT-10
Zone	Etc/GMT-9	9	-	GMT-9
Zone	Etc/GMT-8	8	-	GMT-8
Zone	Etc/GMT-7	7	-	GMT-7
Zone	Etc/GMT-6	6	-	GMT-6
Zone	Etc/GMT-5	5	-	GMT-5
Zone	Etc/GMT-4	4	-	GMT-4
Zone	Etc/GMT-3	3	-	GMT-3
Zone	Etc/GMT-2	2	-	GMT-2
Zone	Etc/GMT-1	1	-	GMT-1
Zone	Etc/GMT+1	-1	-	GMT+1
Zone	Etc/GMT+2	-2	-	GMT+2
Zone	Etc/GMT+3	-3	-	GMT+3
Zone	Etc/GMT+4	-4	-	GMT+4
Zone	Etc/GMT+5	-5	-	GMT+5
Zone	Etc/GMT+6	-6	-	GMT+6
Zone	Etc/GMT+7	-7	-	GMT+7
Zone	Etc/GMT+8	-8	-	GMT+8
Zone	Etc/GMT+9	-9	-	GMT+9
Zone	Etc/GMT+10	-10	-	GMT+10
Zone	Etc/GMT+11	-11	-	GMT+11
Zone	Etc/GMT+12	-12	-	GMT+12


However, Java uses the real life GMT offset convention for display names rather than the POSIX one (e.g., GMT-8 means 8 hours behind GMT.) By the way, the output as ACTUAL BEHAVIOR in Description is incorrect.

EXPECTED VERSUS ACTUAL BEHAVIOR :
"Etc/GMT-8"  ->  GMT-8:00
"Etc/GMT+8" ->  GMT+8:00

should be:

EXPECTED VERSUS ACTUAL BEHAVIOR :
"Etc/GMT-8"  ->  GMT+08:00
"Etc/GMT+8" ->  GMT-08:00

as seen below.

America/Dawson
America/Ensenada
America/Los_Angeles
America/Tijuana
America/Vancouver
America/Whitehorse
Canada/Pacific
Canada/Yukon
Etc/GMT+8
Mexico/BajaNorte
PST
PST8PDT
Pacific/Pitcairn
SystemV/PST8
SystemV/PST8PDT
US/Pacific
US/Pacific-New
Antarctica/Casey
Asia/Brunei
Asia/Chongqing
Asia/Chungking
Asia/Harbin
Asia/Hong_Kong
Asia/Irkutsk
Asia/Kashgar
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Macao
Asia/Macau
Asia/Makassar
Asia/Manila
Asia/Shanghai
Asia/Singapore
Asia/Taipei
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Australia/Perth
Australia/West
CTT
Etc/GMT-8
Hongkong
PRC
Singapore

GMT+08:00
GMT-08:00

###@###.### 2003-02-06
                                     
2003-02-06



Hardware and Software, Engineered to Work Together