Skip to content

Commit

Permalink
Update tzdb handling (#789)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jodastephen authored Sep 15, 2024
1 parent 54b3d1c commit f38a08e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/joda/time/tz/ZoneInfoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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("CET"));
assertEquals("2007-03-04 12:30 CET]", f.print(dt));
assertEquals(dt, f.parseDateTime("2007-03-04 12:30 CET]"));
}

public void test_printParseZoneBahiaBanderas() {
Expand Down

0 comments on commit f38a08e

Please sign in to comment.