Skip to content

Commit d971abc

Browse files
authored
CLDR-19419 ordinal dates: update report (#5685)
1 parent 7457ddc commit d971abc

3 files changed

Lines changed: 90 additions & 10 deletions

File tree

tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRURLS.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public enum Special {
166166
public static final String TZ_CITY_NAMES =
167167
"https://cldr.unicode.org/translation/time-zones-and-city-names";
168168
public static final String UNITS_HELP = "https://cldr.unicode.org/translation/units";
169+
public static final String ORDINAL_DATE_HELP =
170+
"https://cldr.unicode.org/translation#ordinal-days-in-dates";
169171
/*
170172
* TODO: UNITS_MISC_HELP, formerly "https://cldr.unicode.org/translation/units-1/misc",
171173
* now temporarily (?) the same as UNITS_HELP until a distinct URL is identified
@@ -239,7 +241,7 @@ public final String forXpathHexId(CLDRLocale locale, String hexid) {
239241
* please use CLDRLocale instead
240242
*
241243
* @param locale
242-
* @param hexid
244+
* @param hexid (or headerId, see {@link PathHeader#getSectionId()})
243245
* @return
244246
*/
245247
public final String forXpathHexId(String locale, PathHeader.PageId page, String hexid) {

tools/cldr-code/src/main/java/org/unicode/cldr/util/DateTimeFormats.java

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import com.ibm.icu.text.MessageFormat;
1111
import com.ibm.icu.text.SimpleDateFormat;
1212
import com.ibm.icu.text.UnicodeSet;
13+
import com.ibm.icu.util.Calendar;
1314
import com.ibm.icu.util.DateInterval;
15+
import com.ibm.icu.util.GregorianCalendar;
1416
import com.ibm.icu.util.ICUUncheckedIOException;
1517
import com.ibm.icu.util.Output;
1618
import com.ibm.icu.util.TimeZone;
@@ -23,6 +25,7 @@
2325
import java.util.Date;
2426
import java.util.EnumSet;
2527
import java.util.LinkedHashSet;
28+
import java.util.Locale;
2629
import java.util.Map;
2730
import java.util.Map.Entry;
2831
import java.util.Set;
@@ -960,11 +963,23 @@ private String getAvailableFormatPath(String skeleton) {
960963
return path;
961964
}
962965

966+
/**
967+
* @returns a HTML snippet that links to view a specfic XPath
968+
*/
963969
public String getFixFromPath(String path) {
964970
String result = PathHeader.getLinkedView(surveyUrl, file, path);
965971
return result == null ? "" : result;
966972
}
967973

974+
/**
975+
* @returns HTML snippet that links to view a specific header
976+
*/
977+
public String getFixHeaderFromPath(String path) {
978+
final CLDRConfig config = CLDRConfig.getInstance();
979+
final PathHeader ph = PathHeader.getFactory(config.getEnglish()).fromPath(path);
980+
return ph.getLinkedHeaderView(config.urls(), file.getLocaleID());
981+
}
982+
968983
/**
969984
* Add a table of date comparisons
970985
*
@@ -988,6 +1003,9 @@ public void addDateTable(CLDRFile english, Appendable output) {
9881003
"thu",
9891004
"fri",
9901005
"sat");
1006+
output.append("<h2>" + hackDoubleLinked("Ordinal Dates") + "</h2>\n");
1007+
addOrdinalDateSubtable(output);
1008+
9911009
output.append("<h2>" + hackDoubleLinked("Months") + "</h2>\n");
9921010
addDateSubtable(
9931011
"//ldml/dates/calendars/calendar[@type=\"CALENDAR\"]/months/monthContext[@type=\"FORMAT\"]/monthWidth[@type=\"WIDTH\"]/month[@type=\"TYPE\"]",
@@ -1079,11 +1097,10 @@ private void addDateSubtable(String path, CLDRFile english, Appendable output, S
10791097
}
10801098

10811099
private static final boolean RETIRE = false;
1082-
private static final String LOCALES = ".*"; // "da|zh|de|ta";
10831100

10841101
/**
1085-
* Produce a set of static tables from the vxml data. Only a stopgap until the above is
1086-
* integrated into ST.
1102+
* Creates static HTML files in: ../cldr-staging/docs/charts/VERSION/verify/dates these
1103+
* correspond to the Date Time report in the Survey Tool.
10871104
*
10881105
* @param args
10891106
* @throws IOException
@@ -1126,6 +1143,7 @@ public static void main(String[] args) throws IOException {
11261143
}
11271144

11281145
writeCss(DIR);
1146+
System.out.println(String.format("Writing %d locale(s) to %s", sorted.size(), DIR));
11291147
PrintWriter out;
11301148
// http://st.unicode.org/cldr-apps/survey?_=LOCALE&x=r_datetime&calendar=gregorian
11311149
int oldFirst = 0;
@@ -1156,9 +1174,7 @@ public static void main(String[] args) throws IOException {
11561174
+ name
11571175
+ "</h1>"
11581176
+ "<p><a href='index.html'>Index</a></p>\n"
1159-
+ "<p>The following chart shows typical usage of date and time formatting with the Gregorian calendar and default number system. "
1160-
+ "<i>There is important information on <a target='CLDR_ST_DOCS' href='http://cldr.unicode.org/translation/date-time-review'>Date/Time Review</a>, "
1161-
+ "so please read that page before starting!</i></p>\n");
1177+
+ "<p>The following chart shows typical usage of date and time formatting with the Gregorian calendar and default number system.</p>\n");
11621178
formats.addTable(english, out);
11631179
formats.addDateTable(englishFile, out);
11641180
formats.addDayPeriods(englishFile, out);
@@ -1209,10 +1225,11 @@ public static void writeCss(String directory) throws IOException {
12091225
out.println(
12101226
".dtf-table, .dtf-int {margin-left:auto; margin-right:auto; border-collapse:collapse;}\n"
12111227
+ ".dtf-table, .dtf-s, .dtf-nopad, .dtf-fix, .dtf-th, .dtf-h, .dtf-sep, .dtf-left, .dtf-int {border:1px solid gray;}\n"
1212-
+ ".dtf-th {background-color:#EEE; padding:4px}\n"
1228+
+ ".dtf-th, .dtf-table th {background-color:#EEE; padding:4px}\n"
12131229
+ ".dtf-s, .dtf-nopad, .dtf-fix {padding:3px; text-align:center}\n"
12141230
+ ".dtf-sep {background-color:#EEF; text-align:center}\n"
12151231
+ ".dtf-s {text-align:center;}\n"
1232+
+ ".dtf-highlight-cell td:hover {\tbackground-color:#446e9b;\n\tcolor:white;\n}\n"
12161233
+ ".dtf-int {width:100%; height:100%}\n"
12171234
+ ".dtf-fix {width:1px}\n"
12181235
+ ".dtf-left {text-align:left;}\n"
@@ -1423,4 +1440,40 @@ static void writeIndexMap(Map<String, String> nameToFile, PrintWriter index) {
14231440
}
14241441
index.println("</div></body></html>");
14251442
}
1443+
1444+
void addOrdinalDateSubtable(Appendable output) throws IOException {
1445+
output.append(
1446+
String.format(
1447+
"<p>%s To fix, see: %s.</p>\n",
1448+
"Review this set of 31 dates. For help, see "
1449+
+ CLDRURLS.docLink(CLDRURLS.ORDINAL_DATE_HELP, "Help"),
1450+
getFixHeaderFromPath(
1451+
"//ldml/dates/calendars/calendar[@type=\"generic\"]/dayOfMonths/dayOfMonthContext[@type=\"format\"]/dayOfMonthWidth[@type=\"abbreviated\"]/dayOfMonth[@ordinal=\"other\"]s")));
1452+
final String pat = "MMMddd"; // Jan 4th
1453+
final String patString = generator.getBestPattern(pat);
1454+
final SimpleDateFormat df = icuServiceBuilder.getDateFormat("gregorian", patString);
1455+
final SimpleDateFormat detailDf =
1456+
icuServiceBuilderEnglish.getDateFormat("gregorian", "E, MMM d"); // Wed, Mar 4
1457+
df.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
1458+
// we'll use Mar 2026
1459+
output.append("<table class='dtf-table dtf-highlight-cell'><tbody>\n <tr>\n");
1460+
Calendar c = new GregorianCalendar(Locale.ENGLISH);
1461+
for (int i = 1; i <= 31; i++) {
1462+
c.set(2026, Calendar.MARCH, i, 12, 0, 0);
1463+
final Date d = c.getTime();
1464+
String fmt = ICUServiceBuilder.formatWithOrdinalHack(df, "gregorian", d, file);
1465+
String detailDate =
1466+
ICUServiceBuilder.formatWithOrdinalHack(detailDf, "gregorian", d, file);
1467+
output.append(
1468+
String.format(
1469+
" <td style='padding: .25em;' title='English: %s'>",
1470+
detailDate))
1471+
.append(fmt)
1472+
.append("</td>\n");
1473+
if (i < 31 && i % 7 == 0) {
1474+
output.append(" </tr>\n <tr>\n");
1475+
}
1476+
}
1477+
output.append(" </tr>\n</tbody></table>\n");
1478+
}
14261479
}

tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@
4343
* tool.
4444
*/
4545
public class PathHeader implements Comparable<PathHeader> {
46+
4647
/** Link to a section. Commenting out the page switch for now. */
4748
public static final String SECTION_LINK = "<a " + /* "target='CLDR_ST-SECTION' "+*/ "href='";
4849

50+
private static final String SECTION_LINK_CLOSE = "'><em>view</em></a>";
51+
4952
static boolean UNIFORM_CONTINENTS = true;
5053
static Factory factorySingleton = null;
5154

@@ -559,6 +562,18 @@ public String getHeader() {
559562
return header == null ? "" : header;
560563
}
561564

565+
// see also cldrTable.mjs HEADER_ID_PREFIX
566+
public static final String HEADER_ID_PREFIX = "header_";
567+
568+
/**
569+
* see also cldrTable.mjs getHeaderId()
570+
*
571+
* @returns string such as "header_DayOfMonth_abbreviated_Formatting"
572+
*/
573+
public String getHeaderId() {
574+
return HEADER_ID_PREFIX + getHeader().replaceAll("[^a-zA-Z0-9]+", "_");
575+
}
576+
562577
public String getCode() {
563578
return code;
564579
}
@@ -2534,11 +2549,21 @@ public static String getUrl(String baseUrl, String locale, String path) {
25342549
public static String getLinkedView(String baseUrl, CLDRFile file, String path) {
25352550
return SECTION_LINK
25362551
+ PathHeader.getUrl(baseUrl, file.getLocaleID(), path)
2537-
+ "'><em>view</em></a>";
2552+
+ SECTION_LINK_CLOSE;
25382553
}
25392554

25402555
public static String getLinkedView(CLDRURLS urls, CLDRFile file, String path) {
2541-
return SECTION_LINK + urls.forXpath(file.getLocaleID(), path) + "'><em>view</em></a>";
2556+
return SECTION_LINK + urls.forXpath(file.getLocaleID(), path) + SECTION_LINK_CLOSE;
2557+
}
2558+
2559+
/**
2560+
* @return HTML that links to the header of this pathHeader
2561+
*/
2562+
public String getLinkedHeaderView(CLDRURLS urls, String locale) {
2563+
// NB: we are passing a header ID in place of a hex id
2564+
return SECTION_LINK
2565+
+ urls.forXpathHexId(locale, getPageId(), getHeaderId())
2566+
+ SECTION_LINK_CLOSE;
25422567
}
25432568

25442569
private static final String SURVEY_URL = CLDRConfig.getInstance().urls().base();

0 commit comments

Comments
 (0)