Skip to content

Commit

Permalink
CLDR-17147 In dateTimePattern examples with short date, use abbreviat…
Browse files Browse the repository at this point in the history
…ed not full zone (unicode-org#3730)
  • Loading branch information
pedberg-icu authored May 17, 2024
1 parent 6f0bba3 commit 61228dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2335,9 +2335,13 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
// ldml/dates/calendars/calendar[@type="*"]/dateTimeFormats/dateTimeFormatLength[@type="*"]/dateTimeFormat[@type="atTime"]/pattern[@type="standard"]
String formatType =
parts.findAttributeValue("dateTimeFormat", "type"); // "standard" or "atTime"
String length =
parts.findAttributeValue(
"dateTimeFormatLength", "type"); // full, long, medium, short

// For all types, show
// - date (of same length) with a single full time
// - date (of same length) with a single full time, or long time (abbreviated zone) if
// the date is short
// - date (of same length) with a single short time
// For the standard patterns, add
// - date (of same length) with a short time range
Expand Down Expand Up @@ -2369,19 +2373,22 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
return "";
}
String timeFormatXPathPrefix = timeFormatXPathForPrefix.substring(0, tfLengthOffset);
String timeFullFormatXPath =
timeFormatXPathPrefix.concat(
"timeFormatLength[@type=\"full\"]/timeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]");
String timeLongerFormatXPath =
(!length.equals("short"))
? timeFormatXPathPrefix.concat(
"timeFormatLength[@type=\"full\"]/timeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]")
: timeFormatXPathPrefix.concat(
"timeFormatLength[@type=\"long\"]/timeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]");
String timeShortFormatXPath =
timeFormatXPathPrefix.concat(
"timeFormatLength[@type=\"short\"]/timeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]");

String timeFormatValue = cldrFile.getWinningValue(timeFullFormatXPath);
parts = XPathParts.getFrozenInstance(cldrFile.getFullXPath(timeFullFormatXPath));
String timeFormatValue = cldrFile.getWinningValue(timeLongerFormatXPath);
parts = XPathParts.getFrozenInstance(cldrFile.getFullXPath(timeLongerFormatXPath));
String timeNumbersOverride = parts.findAttributeValue("pattern", "numbers");
SimpleDateFormat tff =
SimpleDateFormat tlf =
icuServiceBuilder.getDateFormat(calendar, timeFormatValue, timeNumbersOverride);
tff.setTimeZone(ZONE_SAMPLE);
tlf.setTimeZone(ZONE_SAMPLE);

timeFormatValue = cldrFile.getWinningValue(timeShortFormatXPath);
parts = XPathParts.getFrozenInstance(cldrFile.getFullXPath(timeShortFormatXPath));
Expand All @@ -2399,7 +2406,7 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
List<String> examples = new ArrayList<>();

String dfResult = df.format(DATE_SAMPLE);
String tffResult = tff.format(DATE_SAMPLE);
String tlfResult = tlf.format(DATE_SAMPLE);
String tsfResult = tsf.format(DATE_SAMPLE); // DATE_SAMPLE is in the afternoon

// Handle date plus a single full time.
Expand All @@ -2414,7 +2421,7 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
value,
(Object[])
new String[] {
setBackground("'" + tffResult + "'"),
setBackground("'" + tlfResult + "'"),
setBackground("'" + dfResult + "'")
}));
examples.add(dtf.format(DATE_SAMPLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ public void TestDateTimeComboFormats() {
"//ldml/dates/calendars/calendar[@type=\"gregorian\"]/dateTimeFormats/dateTimeFormatLength[@type=\"long\"]/dateTimeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]");
checkValue(
"DateTimeCombo short std",
"〖❬9/5/99❭, ❬1:25:59 PM Eastern Standard Time❭〗〖❬9/5/99❭, ❬1:25 PM❭〗〖❬9/5/99❭, ❬7:00 AM – 1:25 PM❭〗〖❬today❭, ❬7:00 AM – 1:25 PM❭〗",
"〖❬9/5/99❭, ❬1:25:59 PM EST❭〗〖❬9/5/99❭, ❬1:25 PM❭〗〖❬9/5/99❭, ❬7:00 AM – 1:25 PM❭〗〖❬today❭, ❬7:00 AM – 1:25 PM❭〗",
exampleGenerator,
"//ldml/dates/calendars/calendar[@type=\"gregorian\"]/dateTimeFormats/dateTimeFormatLength[@type=\"short\"]/dateTimeFormat[@type=\"standard\"]/pattern[@type=\"standard\"]");
checkValue(
Expand Down

0 comments on commit 61228dd

Please sign in to comment.