Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Jan 10, 2025
1 parent 9702acc commit cf72f36
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/java.base/share/classes/java/util/TimeZone.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,6 +46,7 @@
import sun.util.calendar.ZoneInfo;
import sun.util.calendar.ZoneInfoFile;
import sun.util.locale.provider.TimeZoneNameUtility;
import sun.util.logging.PlatformLogger;

/**
* {@code TimeZone} represents a time zone offset, and also figures out daylight
Expand Down Expand Up @@ -596,6 +597,11 @@ private ZoneId toZoneId0() {
}

private static TimeZone getTimeZone(String ID, boolean fallback) {
if (ZoneId.SHORT_IDS.containsKey(ID)) {
PlatformLogger.getLogger(TimeZone.class.getName())
.warning("Use of the three-letter time zone ID \"%s\" is deprecated and it will be removed in a future release"
.formatted(ID));
}
TimeZone tz = ZoneInfo.getTimeZone(ID);
if (tz == null) {
tz = parseCustomTimeZone(ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -35,7 +35,8 @@
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TimeZone;

import sun.util.calendar.ZoneInfo;
import sun.util.calendar.ZoneInfoFile;
import sun.util.locale.provider.LocaleProviderAdapter;
import sun.util.locale.provider.LocaleResources;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected String[] getDisplayNameArray(String id, Locale locale) {
case "":
// Fill in empty elements
deriveFallbackName(namesSuper, i, locale,
TimeZone.getTimeZone(id).toZoneId().getRules().isFixedOffset());
ZoneInfo.getTimeZone(id).toZoneId().getRules().isFixedOffset());
break;
case NO_INHERITANCE_MARKER:
// CLDR's "no inheritance marker"
Expand Down Expand Up @@ -131,7 +132,7 @@ protected String[][] getZoneStrings(Locale locale) {

// Derive fallback time zone name according to LDML's logic
private void deriveFallbackNames(String[] names, Locale locale) {
boolean noDST = TimeZone.getTimeZone(names[0]).toZoneId().getRules().isFixedOffset();
boolean noDST = ZoneInfo.getTimeZone(names[0]).toZoneId().getRules().isFixedOffset();

for (int i = INDEX_STD_LONG; i <= INDEX_GEN_SHORT; i++) {
deriveFallbackName(names, i, locale, noDST);
Expand Down
49 changes: 49 additions & 0 deletions test/jdk/java/util/TimeZone/ThreeLetterZoneID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8342550
* @summary Three-letter time zone IDs should output a deprecated warning
* message.
* @library /test/lib
* @build jdk.test.lib.process.ProcessTools
* @run main ThreeLetterZoneID
*/
import java.util.TimeZone;
import jdk.test.lib.process.ProcessTools;

public class ThreeLetterZoneID {
public static void main(String... args) throws Exception {
if (args.length > 0) {
TimeZone.getTimeZone("PST");
} else {
checkWarningMessage();
}
}

public static void checkWarningMessage() throws Exception {
ProcessTools.executeTestJava("ThreeLetterZoneID", "dummy")
.shouldContain("Use of the three-letter time zone ID \"PST\" is deprecated and it will be removed in a future release");
}
}

0 comments on commit cf72f36

Please sign in to comment.