Skip to content

Commit

Permalink
Fixed an edge case where a format is missing
Browse files Browse the repository at this point in the history
In the case where the zone's format (zone abbreviation)
is simply "%s" and the zone has changed from having DST
in the past but not now, then there is no current rule with
which to replace the "%s". The work-around is to find the
last rule that is available and use its format letters as
the format.
  • Loading branch information
ehoogerbeets committed Mar 19, 2020
1 parent 867ef0b commit b0bc19a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
11 changes: 7 additions & 4 deletions java/src/com/ilib/tools/zic/Offset.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public JSONObject getJson(boolean currentOnly)
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
rulesList = rules.getRules();
Rule startRule = null, endRule = null;
Rule startRule = null, endRule = null, lastRule = rulesList.get(rulesList.size()-1);;
for ( i = 0; i < rulesList.size(); i++ ) {
rule = rulesList.get(i);
// check year-1 against the end year to take care of the
Expand Down Expand Up @@ -278,13 +278,16 @@ public JSONObject getJson(boolean currentOnly)
}
json.put("e", wallTime.getJson(currentOnly));
}

if ( startRule == null && endRule == null ) {

if (format.trim().equals("%s")) {
json.put("f", lastRule.getCharacter());
} else if ( startRule == null && endRule == null ) {
// no DST in this time zone, so fix up bogus abbreviations that include the %s when it shouldn't
// replace the %s with S for "Standard time"
json.put("f", format.replace("%s", "S"));
}
}

return json;
}
}
2 changes: 1 addition & 1 deletion js/data/locale/zoneinfo/Africa/Windhoek.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"f": "S",
"f": "WAT",
"o": "2:0",
"c": "NA",
"n": "Namibia {c} Time"
Expand Down
2 changes: 1 addition & 1 deletion js/data/locale/zoneinfo/America/Belize.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"f": "S",
"f": "CST",
"o": "-6:0",
"c": "BZ",
"n": "Central America {c} Time"
Expand Down
2 changes: 1 addition & 1 deletion js/data/locale/zoneinfo/Antarctica/Troll.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"r": "l0",
"t": "3:0"
},
"f": "{c}",
"f": "+00",
"o": "0:0",
"s": {
"c": "+02",
Expand Down
18 changes: 9 additions & 9 deletions js/test/date/testdatefmt_af_NA.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45 CAT");
test.equal(fmt.format(date), "13:45 WAT");
test.done();
},

Expand All @@ -1249,7 +1249,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45 CAT");
test.equal(fmt.format(date), "13:45 WAT");
test.done();
},

Expand Down Expand Up @@ -1292,7 +1292,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45:37 CAT");
test.equal(fmt.format(date), "13:45:37 WAT");
test.done();
},

Expand All @@ -1316,7 +1316,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45:37 CAT");
test.equal(fmt.format(date), "13:45:37 WAT");
test.done();
},

Expand Down Expand Up @@ -1474,7 +1474,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45 CAT");
test.equal(fmt.format(date), "13:45 WAT");
test.done();
},

Expand All @@ -1498,7 +1498,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45 CAT");
test.equal(fmt.format(date), "13:45 WAT");
test.done();
},

Expand Down Expand Up @@ -1542,7 +1542,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45:37 CAT");
test.equal(fmt.format(date), "13:45:37 WAT");
test.done();
},

Expand All @@ -1566,7 +1566,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45:37 CAT");
test.equal(fmt.format(date), "13:45:37 WAT");
test.done();
},

Expand All @@ -1590,7 +1590,7 @@ module.exports.testdatefmt_af_NA = {
second: 37,
millisecond: 0
});
test.equal(fmt.format(date), "13:45:37 CAT");
test.equal(fmt.format(date), "13:45:37 WAT");
test.done();
},

Expand Down

0 comments on commit b0bc19a

Please sign in to comment.