From baea485d759bbf65891b959a573a6688f97cfecf Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 15 Sep 2024 21:46:36 +0100 Subject: [PATCH] Update tzdb handling * Update parser and tests to handle changes to TZDB data * WET, CET and EET European zones are saved * MET zone is mapped to CET * American zones like EST will be auto-normalized --- .../org/joda/time/tz/ZoneInfoCompiler.java | 12 ++++++++-- .../format/TestDateTimeFormatterBuilder.java | 24 +++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/joda/time/tz/ZoneInfoCompiler.java b/src/main/java/org/joda/time/tz/ZoneInfoCompiler.java index 49c793c2e..57a7944d5 100644 --- a/src/main/java/org/joda/time/tz/ZoneInfoCompiler.java +++ b/src/main/java/org/joda/time/tz/ZoneInfoCompiler.java @@ -636,7 +636,13 @@ public void parseDataFile(BufferedReader in, boolean backward) throws IOExceptio // links in "backward" are deprecated names // links in other files should be kept // special case a few to try to repair terrible damage to tzdb - if (backward || alias.equals("US/Pacific-New") || alias.startsWith("Etc/") || alias.equals("GMT")) { + if (alias.equals("WET") || alias.equals("CET") || alias.equals("EET")) { + iGoodLinks.add(real); + iGoodLinks.add(alias); + } else if (alias.equals("MET")) { + iBackLinks.add("CET"); // map MET -> CET (not Europe/Brussels) + iBackLinks.add(alias); + } else if (backward || alias.equals("US/Pacific-New") || alias.startsWith("Etc/") || alias.equals("GMT")) { iBackLinks.add(real); iBackLinks.add(alias); } else { @@ -962,7 +968,9 @@ public void addRecurring(DateTimeZoneBuilder builder, int standardMillis, String // if negative SAVE values, then patch standard millis and name format if (negativeSave < 0) { - System.out.println("Fixed negative save values for rule '" + iRules.get(0).iName + "'"); + if (ZoneInfoLogger.verbose()) { + System.out.println("Fixed negative save values for rule '" + iRules.get(0).iName + "'"); + } standardMillis += negativeSave; int slashPos = nameFormat.indexOf("/"); if (slashPos > 0) { diff --git a/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java b/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java index 102760d62..a95f95b3c 100644 --- a/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java +++ b/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java @@ -21,15 +21,15 @@ import java.util.Locale; import java.util.Map; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import org.joda.time.DateTime; import org.joda.time.DateTimeFieldType; import org.joda.time.DateTimeZone; import org.joda.time.LocalDateTime; +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; +import junit.framework.TestSuite; + /** * This class is a Junit unit test for DateTimeFormatterBuilder. * @@ -547,24 +547,24 @@ public void test_printParseZoneEtcGMT10_suffix() { assertEquals(dt, f.parseDateTime("2007-03-04 12:30 Etc/GMT+10]")); } - public void test_printParseZoneMET() { + public void test_printParseZoneCET() { DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd HH:mm ZZZ"); DateTimeFormatter f = bld.toFormatter(); - DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, DateTimeZone.forID("MET")); - assertEquals("2007-03-04 12:30 MET", f.print(dt)); - assertEquals(dt, f.parseDateTime("2007-03-04 12:30 MET")); + DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, DateTimeZone.forID("CET")); + assertEquals("2007-03-04 12:30 CET", f.print(dt)); + assertEquals(dt, f.parseDateTime("2007-03-04 12:30 CET")); } - public void test_printParseZoneMET_suffix() { + public void test_printParseZoneCET_suffix() { DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd HH:mm ZZZ").appendLiteral(']'); DateTimeFormatter f = bld.toFormatter(); - DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, DateTimeZone.forID("MET")); - assertEquals("2007-03-04 12:30 MET]", f.print(dt)); - assertEquals(dt, f.parseDateTime("2007-03-04 12:30 MET]")); + DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, DateTimeZone.forID("CMET")); + assertEquals("2007-03-04 12:30 CET]", f.print(dt)); + assertEquals(dt, f.parseDateTime("2007-03-04 12:30 CET]")); } public void test_printParseZoneBahiaBanderas() {