Skip to content

Commit

Permalink
Update tzdb handling
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 committed Sep 15, 2024
1 parent 0a264f1 commit 7d0c672
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/joda/time/tz/ZoneInfoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static boolean test(String id, DateTimeZone tz) {
return false;
}

if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey) && !"%z".equals(nextKey))) {
System.out.println("*s* Error in " + tz.getID() + " "
+ new DateTime(millis,
ISOChronology.getInstanceUTC())
Expand Down Expand Up @@ -501,7 +501,7 @@ public Map<String, DateTimeZone> compile(File outputDir, File[] sources) throws
}
}

// store "back" links as aliases (where name is permanently mapped
// store "back" links as aliases (where name is permanently mapped)
for (int pass = 0; pass < 2; pass++) {
for (int i = 0; i < iBackLinks.size(); i += 2) {
String id = iBackLinks.get(i);
Expand Down 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 @@ -948,7 +954,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 @@ -553,8 +553,8 @@ public void test_printParseZoneMET() {
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"));
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() {
Expand All @@ -563,8 +563,8 @@ public void test_printParseZoneMET_suffix() {
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]"));
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 7d0c672

Please sign in to comment.