Skip to content

Commit

Permalink
CLDR-17758 DDL: expand VettingViewerSummary for unaffiliated TC to al…
Browse files Browse the repository at this point in the history
…l non-TC locales (#3822)
  • Loading branch information
srl295 committed Jun 25, 2024
1 parent e899b78 commit 7d65bac
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 24 deletions.
27 changes: 5 additions & 22 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.ibm.icu.dev.util.ElapsedTimer;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.ListFormatter;
import com.ibm.icu.text.RelativeDateTimeFormatter;
import com.ibm.icu.text.UnicodeSet;
import com.ibm.icu.util.ULocale;
import java.io.BufferedReader;
Expand Down Expand Up @@ -42,7 +41,6 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -90,6 +88,7 @@
import org.unicode.cldr.util.SpecialLocales.Type;
import org.unicode.cldr.util.StackTracker;
import org.unicode.cldr.util.SupplementalDataInfo;
import org.unicode.cldr.util.TimeDiff;
import org.unicode.cldr.web.UserRegistry.User;
import org.unicode.cldr.web.WebContext.HTMLDirection;
import org.unicode.cldr.web.api.Summary;
Expand Down Expand Up @@ -3536,27 +3535,11 @@ public static String durationDiff(long a) {
return timeDiff(System.currentTimeMillis() - a);
}

/**
* @returns string representation of the difference between the two millisecond values
*/
private static String timeDiff(long a, long b) {

final long ONE_DAY = 86400 * 1000;
final long A_LONG_TIME = ONE_DAY;
if ((b - a) > (A_LONG_TIME)) {
double del = (b - a);
del /= ONE_DAY;
int days = (int) del;
return RelativeDateTimeFormatter.getInstance(Locale.ENGLISH)
.format(
days,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.DAYS);
} else {
final double hours = (b - a) / (3600.0 * 1000.0);
return RelativeDateTimeFormatter.getInstance(Locale.ENGLISH)
.format(
hours,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.HOURS);
}
return TimeDiff.timeDiff(a, b);
}

public static String shortClassName(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.unicode.cldr.util.*;
import org.unicode.cldr.util.TimeDiff;
import org.unicode.cldr.web.CLDRProgressIndicator.CLDRProgressTask;
import org.unicode.cldr.web.api.LocaleCompletion;

Expand Down Expand Up @@ -134,7 +135,7 @@ private CLDRProgressCallback(CLDRProgressTask progress, Thread thread) {
private String setRemStr(long now) {
double per = (double) (now - start) / (double) n;
long rem = (long) ((maxn - n) * per);
String remStr = ElapsedTimer.elapsedTime(now, now + rem) + " " + "remaining";
String remStr = "Estimated completion: " + TimeDiff.timeDiff(now, now - rem);
if (rem <= 1500) { // Less than 1.5 seconds remaining
remStr = "Finishing...";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.ibm.icu.dev.util;

import com.google.common.base.Stopwatch;
import org.unicode.cldr.util.TimeDiff;

/**
* simple class to calculate elapsed times.
Expand Down Expand Up @@ -47,6 +48,6 @@ public static String elapsedTime(long startMs) {
*/
@Deprecated
public static String elapsedTime(long startMs, long endMs) {
return String.format("[%d ms]", endMs - startMs);
return TimeDiff.timeDiff(startMs, endMs);
}
}
75 changes: 75 additions & 0 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/TimeDiff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.unicode.cldr.util;

import com.ibm.icu.text.MeasureFormat;
import com.ibm.icu.text.MeasureFormat.FormatWidth;
import com.ibm.icu.text.RelativeDateTimeFormatter;
import com.ibm.icu.util.Measure;
import com.ibm.icu.util.MeasureUnit;
import com.ibm.icu.util.ULocale;
import java.util.Locale;

public class TimeDiff {
public static String timeDiff(long a) {
return timeDiff(a, System.currentTimeMillis());
}

public static String durationDiff(long a) {
return timeDiff(System.currentTimeMillis() - a);
}

private static final long ONE_SECOND = 1 * 1000;
private static final long ONE_MINUTE = 60 * 1000;
private static final long ONE_HOUR = 3600 * 1000;
private static final long ONE_DAY = 86400 * 1000;
private static final double ONE_YEAR = ONE_DAY * 364.25;

/**
* @returns string representation of the difference between the two millisecond values
*/
public static String timeDiff(long a, long b) {
double del = (b - a);
final RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(Locale.ENGLISH);

if (del > ONE_YEAR) {
del /= ONE_YEAR; // approximate
int years = (int) del;
return fmt.format(
years,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.YEARS);
} else if (del > (ONE_DAY)) {
// more than a day: reference in days
del /= ONE_DAY;
int days = (int) del;
return fmt.format(
days,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.DAYS);
} else if (del > ONE_HOUR) {
final double hours = (b - a) / (ONE_HOUR);
return fmt.format(
hours,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.HOURS);
} else if (del > ONE_MINUTE) {
final double minutes = (b - a) / (ONE_MINUTE);
return fmt.format(
minutes,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.MINUTES);

} else if (del > ONE_SECOND) {

final double seconds = (b - a) / (ONE_SECOND);
return fmt.format(
seconds,
RelativeDateTimeFormatter.Direction.LAST,
RelativeDateTimeFormatter.RelativeUnit.SECONDS);

} else {
// fall back to milliseconds
return MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.NARROW)
.format(new Measure(del, MeasureUnit.MILLISECOND));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,27 @@ private void writeSummaryTable(

private Map<String, String> getSortedNames(Organization org, Level desiredLevel) {
Map<String, String> sortedNames = new TreeMap<>(CLDRConfig.getInstance().getCollator());
LocalesWithExplicitLevel cldrLocale =
new LocalesWithExplicitLevel(Organization.cldr, desiredLevel);

// A user in the Unaffiliated organization can access a list with all non-TC locales.
if (org == Organization.unaffiliated && desiredLevel == Level.BASIC) {
for (String localeID : cldrFactory.getAvailable()) {
final CLDRLocale loc = CLDRLocale.getInstance(localeID);
if (SubmissionLocales.isTcLocale(loc)) continue; // skip TC locales
if (defaultContentLocales.contains(localeID)) continue; // skip DC
final SpecialLocales.Type type = SpecialLocales.getType(loc);
if (type != null) continue; // skip any 'special' locales, algorithmic, readonly etc

sortedNames.put(getName(localeID), localeID);
}
return sortedNames;
}

if (org == Organization.unaffiliated) {
return sortedNames; // empty
}

// TODO Fix HACK
// We are going to ignore the predicate for now, just using the locales that have explicit
// coverage.
Expand Down

0 comments on commit 7d65bac

Please sign in to comment.