Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-13864 Add night unit #3713

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macchiati - Why is night different than day here? Day has '{0} per day'

</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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a big party!

.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
Loading