Skip to content

Commit 9112c2e

Browse files
authored
CLDR-17298 Add parts per billion (#3716)
1 parent 903f21c commit 9112c2e

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed

common/main/en.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6886,6 +6886,11 @@ annotations.
68866886
<unitPattern count="one">{0} part per million</unitPattern>
68876887
<unitPattern count="other">{0} parts per million</unitPattern>
68886888
</unit>
6889+
<unit type="concentr-portion-per-1e9">
6890+
<displayName>parts per billion</displayName>
6891+
<unitPattern count="one">{0} part per billion</unitPattern>
6892+
<unitPattern count="other">{0} parts per billion</unitPattern>
6893+
</unit>
68896894
<unit type="concentr-percent">
68906895
<displayName>percent</displayName>
68916896
<unitPattern count="one">{0} percent</unitPattern>
@@ -7970,6 +7975,11 @@ annotations.
79707975
<unitPattern count="one">{0} ppm</unitPattern>
79717976
<unitPattern count="other">{0} ppm</unitPattern>
79727977
</unit>
7978+
<unit type="concentr-portion-per-1e9">
7979+
<displayName>parts/billion</displayName>
7980+
<unitPattern count="one">{0} ppb</unitPattern>
7981+
<unitPattern count="other">{0} ppb</unitPattern>
7982+
</unit>
79737983
<unit type="concentr-percent">
79747984
<displayName>percent</displayName>
79757985
<unitPattern count="one">{0}%</unitPattern>
@@ -9051,6 +9061,11 @@ annotations.
90519061
<unitPattern count="one">{0}ppm</unitPattern>
90529062
<unitPattern count="other">{0}ppm</unitPattern>
90539063
</unit>
9064+
<unit type="concentr-portion-per-1e9">
9065+
<displayName>ppb</displayName>
9066+
<unitPattern count="one">{0}ppb</unitPattern>
9067+
<unitPattern count="other">{0}ppb</unitPattern>
9068+
</unit>
90549069
<unit type="concentr-percent">
90559070
<displayName>%</displayName>
90569071
<unitPattern count="one">{0}%</unitPattern>

common/main/root.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5101,6 +5101,10 @@ Warnings: All cp values have U+FE0F characters removed. See /annotationsDerived/
51015101
<displayName>ppm</displayName>
51025102
<unitPattern count="other">{0} ppm</unitPattern>
51035103
</unit>
5104+
<unit type="concentr-portion-per-1e9">
5105+
<displayName>ppb</displayName>
5106+
<unitPattern count="other">{0} ppb</unitPattern>
5107+
</unit>
51045108
<unit type="concentr-percent">
51055109
<displayName>%</displayName>
51065110
<unitPattern count="other">{0}%</unitPattern>

common/validity/unit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ For terms of use, see http://www.unicode.org/copyright.html
239239
volume-sai
240240
volume-to-jp
241241
volume-koku
242+
concentr-portion-per-1e9
242243
mass-fun
243244
duration-night
244245
speed-light-speed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,7 @@ private static final class UnitOrderHolder {
18711871
"volume-koku",
18721872
"speed-light-speed",
18731873
"mass-fun",
1874+
"concentr-portion-per-1e9",
18741875
"duration-night"))
18751876
.freeze();
18761877
}

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ public int compare(String o1, String o2) {
10731073
}
10741074

10751075
Comparator<String> UNIT_COMPARATOR = new UnitComparator();
1076+
static final Pattern TRAILING_ZEROS = Pattern.compile("0+$");
10761077

10771078
/** Only handles the canonical units; no kilo-, only normalized, etc. */
10781079
// Thus we do not need to handle specials here
@@ -1174,7 +1175,7 @@ public String toString() {
11741175
for (int i = 1; i >= 0; --i) { // two passes, numerator then den.
11751176
boolean positivePass = i > 0;
11761177
if (positivePass && !factor.numerator.equals(BigInteger.ONE)) {
1177-
builder.append(factor.numerator);
1178+
builder.append(shortConstant(factor.numerator));
11781179
}
11791180

11801181
Map<String, Integer> target = positivePass ? numUnitsToPowers : denUnitsToPowers;
@@ -1190,7 +1191,7 @@ public String toString() {
11901191
firstDenominator = false;
11911192
builder.append("per-");
11921193
if (!factor.denominator.equals(BigInteger.ONE)) {
1193-
builder.append(factor.denominator).append('-');
1194+
builder.append(shortConstant(factor.denominator)).append('-');
11941195
}
11951196
}
11961197
}
@@ -1213,10 +1214,35 @@ public String toString() {
12131214
}
12141215
builder.append(unit);
12151216
}
1217+
if (!positivePass
1218+
&& firstDenominator
1219+
&& !factor.denominator.equals(BigInteger.ONE)) {
1220+
builder.append("-per-").append(shortConstant(factor.denominator));
1221+
}
12161222
}
12171223
return builder.toString();
12181224
}
12191225

1226+
/**
1227+
* Return a string format. If larger than 7 digits, use 1eN format.
1228+
*
1229+
* @param source
1230+
* @return
1231+
*/
1232+
public String shortConstant(BigInteger source) {
1233+
// don't bother optimizing
1234+
String result = source.toString();
1235+
if (result.length() < 8) {
1236+
return result;
1237+
}
1238+
Matcher matcher = TRAILING_ZEROS.matcher(result);
1239+
if (matcher.find()) {
1240+
int zeroCount = matcher.group().length();
1241+
return result.substring(0, result.length() - zeroCount) + "e" + zeroCount;
1242+
}
1243+
return result;
1244+
}
1245+
12201246
public String toString(
12211247
LocaleStringProvider resolvedFile,
12221248
String width,

tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,10 @@ public void TestUnitOrder() {
31973197

31983198
checkNormalization("test case", "newton-meter");
31993199
checkNormalization("test case", "acre-foot");
3200+
checkNormalization("test case", "portion-per-1e9");
3201+
checkNormalization("test case", "portion-per-1000");
3202+
checkNormalization("test case", "1e9-meter");
3203+
checkNormalization("test case", "1000-meter");
32003204

32013205
String stdAcre = converter.getStandardUnit("acre");
32023206

0 commit comments

Comments
 (0)