Skip to content

Commit

Permalink
CLDR-13864 Add night unit (#3713)
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati authored May 13, 2024
1 parent 73d9bd5 commit 5ae2965
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
18 changes: 18 additions & 0 deletions common/main/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7021,6 +7021,12 @@ annotations.
<unitPattern count="other">{0} days</unitPattern>
<perUnitPattern>{0} per day</perUnitPattern>
</unit>
<unit type="duration-night">
<displayName>nights</displayName>
<unitPattern count="one">{0} night</unitPattern>
<unitPattern count="other">{0} nights</unitPattern>
<perUnitPattern>{0}/night</perUnitPattern>
</unit>
<unit type="duration-hour">
<displayName>hours</displayName>
<unitPattern count="one">{0} hour</unitPattern>
Expand Down Expand Up @@ -8094,6 +8100,12 @@ annotations.
<unitPattern count="other">{0} days</unitPattern>
<perUnitPattern>{0}/d</perUnitPattern>
</unit>
<unit type="duration-night">
<displayName>nights</displayName>
<unitPattern count="one">{0} night</unitPattern>
<unitPattern count="other">{0} nights</unitPattern>
<perUnitPattern>{0}/night</perUnitPattern>
</unit>
<unit type="duration-hour">
<displayName>hours</displayName>
<unitPattern count="one">{0} hr</unitPattern>
Expand Down Expand Up @@ -9164,6 +9176,12 @@ annotations.
<unitPattern count="other">{0}d</unitPattern>
<perUnitPattern>{0}/d</perUnitPattern>
</unit>
<unit type="duration-night">
<displayName>nights</displayName>
<unitPattern count="one">{0}night</unitPattern>
<unitPattern count="other">{0}nights</unitPattern>
<perUnitPattern>{0}/night</perUnitPattern>
</unit>
<unit type="duration-hour">
<displayName>hour</displayName>
<unitPattern count="one">{0}h</unitPattern>
Expand Down
5 changes: 5 additions & 0 deletions common/main/root.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5222,6 +5222,11 @@ Warnings: All cp values have U+FE0F characters removed. See /annotationsDerived/
<unit type="duration-day-person">
<alias source="locale" path="../unit[@type='duration-day']"/>
</unit>
<unit type="duration-night">
<displayName>night</displayName>
<unitPattern count="other">{0} night</unitPattern>
<perUnitPattern>{0}/night</perUnitPattern>
</unit>
<unit type="duration-hour">
<displayName>hr</displayName>
<unitPattern count="other">{0} h</unitPattern>
Expand Down
8 changes: 7 additions & 1 deletion common/supplemental/units.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ For terms of use, see http://www.unicode.org/copyright.html
<unitQuantity baseUnit='second' quantity='duration' status='simple'/> <!-- use duration because 'time' can mean absolute time -->
<unitQuantity baseUnit='second-ampere' quantity='electric-charge'/>

<!-- special duration, because months..years are not comparable to seconds -->
<unitQuantity baseUnit='year' quantity='year-duration' status='simple'/> <!-- non-SI but here for ordering -->

<!-- special duration, because nights are not comparable to seconds -->
<unitQuantity baseUnit='night' quantity='night-duration' status='simple'/>

<unitQuantity baseUnit='ampere' quantity='electric-current' status='simple'/>
<unitQuantity baseUnit='ampere-per-square-meter' quantity='current-density'/>
<unitQuantity baseUnit='ampere-per-meter' quantity='magnetic-field-strength'/>
Expand Down Expand Up @@ -141,7 +145,6 @@ For terms of use, see http://www.unicode.org/copyright.html
<unitQuantity baseUnit='pixel-per-meter' quantity='resolution'/>

<unitQuantity baseUnit='em' quantity='typewidth' status='simple'/>

</unitQuantities>
<convertUnits>
<!-- Values where possible from:
Expand Down Expand Up @@ -238,6 +241,9 @@ For terms of use, see http://www.unicode.org/copyright.html
<convertUnit source='decade' baseUnit='year' factor='10' systems="metric_adjacent ussystem uksystem astronomical"/>
<convertUnit source='century' baseUnit='year' factor='100' systems="metric_adjacent ussystem uksystem astronomical"/>

<!-- night-duration -->
<convertUnit source='night' baseUnit='night' systems="metric_adjacent uksystem ussystem"/>

<!-- electric-current -->
<convertUnit source='ampere' baseUnit='ampere' systems="si metric prefixable"/>

Expand Down
1 change: 1 addition & 0 deletions common/validity/unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ For terms of use, see http://www.unicode.org/copyright.html
volume-to-jp
volume-koku
mass-fun
duration-night
</id>
<id type='unit' idStatus='deprecated'>
acceleration-meter-per-second-squared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,8 @@ private static final class UnitOrderHolder {
"volume-sai",
"volume-to-jp",
"volume-koku",
"mass-fun"))
"mass-fun",
"duration-night"))
.freeze();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public Comparator<String> getShortUnitIdComparator() {
"pixel",
"em",
"revolution",
"portion");
"portion",
"night");

public void addQuantityInfo(String baseUnit, String quantity, String status) {
if (baseUnitToQuantity.containsKey(baseUnit)) {
Expand Down Expand Up @@ -230,6 +231,14 @@ public UnitConverter freeze() {
}
}
String quantity = getQuantityFromUnit(base.value, false);
if (quantity == null) {
if (base.value.equals("night")) {
quantity = "duration";
} else {
throw new IllegalArgumentException(
"Can't get quantity from : " + base.value);
}
}
Integer quantityNumericOrder = quantityComparator.getNumericOrder(quantity);
if (quantityNumericOrder == null) { // try the inverse
if (base.value.equals("meter-per-cubic-meter")) { // HACK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ public void TestRationalParse() {
.put("newton-meter", "torque")
.put("pound-force-foot", "torque")
.put("solar-luminosity", "light")
.put("night", "duration")
.build();

public void TestUnitCategory() {
Expand Down Expand Up @@ -4627,13 +4628,18 @@ private void checkUnitLocalePreferencesTestIcu(String rawLine) {
actualUnit = e.getMessage();
actualValueFloat = Float.NaN;
}
if (assertEquals(
String.format(
"ICU unit pref, %s %s %s %s",
sourceUnit, sourceAmount, usage, languageTag),
expectedUnit,
actualUnit)) {
assertEquals("ICU value", (float) expectedAmount, actualValueFloat);
if (!expectedUnit.equals(actualUnit)) {
if (!logKnownIssue("CLDR-17581", "No null from unitPreferences")) {

assertEquals(
String.format(
"ICU unit pref, %s %s %s %s",
sourceUnit, sourceAmount, usage, languageTag),
expectedUnit,
actualUnit);
}
} else if (assertEquals("ICU value", (float) expectedAmount, actualValueFloat)) {
// no other action
} else if (!comment.isBlank()) {
warnln(comment);
}
Expand Down

0 comments on commit 5ae2965

Please sign in to comment.