Skip to content

Releases: elixir-cldr/cldr_units

Cldr Units version 3.1.1

29 Jun 14:14
Compare
Choose a tag to compare

Bug Fixes

  • Ensure that :locale is passed through to Cldr.Numnber.to_string/3. Thanks for the PR to @Zurga. Closes #14.

Cldr Units version 3.1.0

17 May 21:24
Compare
Choose a tag to compare

Enhancements

  • Add Cldr.Unit.to_iolist/3 and Cldr.Unit.to_iolist!/3 to return the formatted unit as an iolist rather than a string. This allows for formatting the number and the unit name differently. It also allows some efficiency in inserting formatted content into a Phoenix workflow since it handles iolists efficiently.

Bug Fixes

  • Fix resolving translatable unit names from strings

  • Fix converting translatable units that have a "per" conversion

Cldr Units version 3.0.1

15 May 14:38
Compare
Choose a tag to compare

Bug Fixes

  • Corrects unit creation when the unit itself is directly translatable (like :kilowatt_hour) but there is no explicit conversion, just an implicit calculated conversion. Thanks to @syfgkjasdkn.

Cldr Units version 3.0.0

12 May 15:53
Compare
Choose a tag to compare

Summary

  • New unit creation including rational numbers

  • Base unit calculation

  • New unit preferences

  • New conversion engine

Breaking changes

  • Cldr.Unit.new/2 is now Cldr.Unit/{2, 3} and it returns a standard {:ok, unit} tuple on success. Use Cldr.Unit.new!/{2,3} if you want to retain the previous behaviour.

  • Removed Cldr.Unit.unit_tree/0

  • Removed Cldr.Unit.units/1

  • Removed Cldr.Unit.compatible_units/2

  • Removed Cldr.Unit.best_match/1

  • Removed Cldr.Unit.jaro_match/1

  • Removed Cldr.Unit.unit_category_map/0 (replaced with Cldr.Unit.base_unit_category_map/0)

Deprecations

  • Deprecate Cldr.Unit.unit_categories/0 in favour of Cldr.Unit.known_unit_categories/0 to be consistent across CLDR.

Enhancements

  • Incorporate CLDR's unit conversion data into the new conversion engine

  • Unit values may now be rational numbers. Conversion data and the results of conversions are executed and retained as rationals. New units can be created with integer, float, Decimal or rational numbers. Conversion to floats is done only when the unit is output via Cldr.Unit.to_string/3 or explicitly through the new function Cldr.Unit.ratio_to_float/1

  • Add an option :usage to Cldr.Unit.new/{2,3}. This defines an expected usage for a given unit that will be applied during localization. The default is :default. See Cldr.Unit.unit_category_map/0 for what usage is defined for a unit category.

  • Add Cldr.Unit.known_measurement_sytems/0 to return the known measurement systems

  • Add Cldr.Unit.Conversion.preferred_units/3 that returns a list of preferred units for a given unit. This makes it straight forward to take a unit and convert it to the units preferred by the user for a given unit type, locale and use case.

  • Add Cldr.Unit.base_category_map/0 that maps base units to their unit categories. For example, map mile_per_hour to :speed or kilogram_square_meter_per_cubic_second_ampere to :voltage. Base units are derived from a unit name and are not normally the concern of the consumer of ex_cldr_units.

Cldr Units version 3.0.0-rc.0

03 May 17:50
Compare
Choose a tag to compare
Pre-release

Summary

  • New unit creation including rational numbers

  • Base unit calculation

  • New unit preferences

  • New conversion engine

Breaking changes

  • Cldr.Unit.new/2 is now Cldr.Unit/{2, 3} and it returns a standard {:ok, unit} tuple on success. Use Cldr.Unit.new!/{2,3} if you want to retain the previous behaviour.

  • Removed Cldr.Unit.unit_tree/0

  • Removed Cldr.Unit.units/1

  • Removed Cldr.Unit.compatible_units/2

  • Removed Cldr.Unit.best_match/1

  • Removed Cldr.Unit.jaro_match/1

  • Removed Cldr.Unit.unit_category_map/0 (replaced with Cldr.Unit.base_unit_category_map/0)

Deprecations

  • Deprecate Cldr.Unit.unit_categories/0 in favour of Cldr.Unit.known_unit_categories/0 to be consistent across CLDR.

Enhancements

  • Incorporate CLDR's unit conversion data into the new conversion engine

  • Unit values may now be rational numbers. Conversion data and the results of conversions are executed and retained as rationals. New units can be created with integer, float, Decimal or rational numbers. Conversion to floats is done only when the unit is output via Cldr.Unit.to_string/3 or explicitly through the new function Cldr.Unit.ratio_to_float/1

  • Add an option :usage to Cldr.Unit.new/{2,3}. This defines an expected usage for a given unit that will be applied during localization. The default is :default. See Cldr.Unit.unit_category_map/0 for what usage is defined for a unit category.

  • Add Cldr.Unit.known_measurement_sytems/0 to return the known measurement systems

  • Add Cldr.Unit.Conversion.preferred_units/3 that returns a list of preferred units for a given unit. This makes it straight forward to take a unit and convert it to the units preferred by the user for a given unit type, locale and use case.

  • Add Cldr.Unit.base_category_map/0 that maps base units to their unit categories. For example, map mile_per_hour to :speed or kilogram_square_meter_per_cubic_second_ampere to :voltage. Base units are derived from a unit name and are not normally the concern of the consumer of ex_cldr_units.

Cldr Units version 2.8.0

27 Jan 13:05
Compare
Choose a tag to compare

Enhancements

  • Support the new Enum.sort/2 in Elixir 1.10. The function Cldr.Math.cmp/2 is deprecated in favour of Cldr.Math.compare/2 that has the same function signature and returns the same result that is compatible with Elixir 1.10.

  • Adds Cldr.Unit.compare/2 that is required for Enum.sort/2 to work as expected with units.

As an example:

iex> alias Cldr.Unit                                                                             Cldr.Unit

iex> unit_list = [Unit.new(:millimeter, 100), Unit.new(:centimeter, 100), Unit.new(:meter, 100), Unit.new(:kilometer, 100)]
[#Unit<:millimeter, 100>, #Unit<:centimeter, 100>, #Unit<:meter, 100>,
 #Unit<:kilometer, 100>]

iex> Enum.sort unit_list, Cldr.Unit
[#Unit<:millimeter, 100>, #Unit<:centimeter, 100>, #Unit<:meter, 100>,
 #Unit<:kilometer, 100>]

iex> Enum.sort unit_list, {:desc, Cldr.Unit}
[#Unit<:kilometer, 100>, #Unit<:meter, 100>, #Unit<:centimeter, 100>,
 #Unit<:millimeter, 100>]

iex> Enum.sort unit_list, {:asc, Cldr.Unit}
[#Unit<:millimeter, 100>, #Unit<:centimeter, 100>, #Unit<:meter, 100>,
 #Unit<:kilometer, 100>]

Cldr Units version 2.7.0

09 Oct 23:58
Compare
Choose a tag to compare

Enhancements

  • Update ex_cldr to version 2.11.0 which encapsulates CLDR version 36.0.0 data.

  • Update minimum Elixir version to 1.6

  • Adds conversion for newton meter, dalton, solar luminosity, pound foot, bar, newton, electron volt, barrel, dunam, decade, mole, pound force, megapascal, pascal, kilopascal, solar radius, therm US, British thermal unit, earth mass.

Cldr Units version 2.6.1

31 Aug 01:26
Compare
Choose a tag to compare

Bug Fixes

  • Fix Cldr.Unit.to_string/3 to ensure that {:ok, string} is returned when formatting a list of units

Cldr Units version 2.6.0

25 Aug 18:51
Compare
Choose a tag to compare

Enhancements

  • Add Cldr.Unit.localize/3 to support converting a given unit into units that are familiar to a given territory. For example, given a unit of #Unit<2, :meter> is would normally be expected to show this as [#Unit<:foot, 5>, #Unit<:inch, 11>]. The data to support these conversions is returned by Cldr.Unit.unit_preferences/0. An example:
  iex> height = Cldr.Unit.new(1.8, :meter)
  iex> Cldr.Unit.localize height, :person, territory: :US, style: :informal
  [#Unit<:foot, 5>, #Unit<:inch, 11>]
  • Note that conversion is dependent on context. The context above is :person reflecting that we are referring to the height of a person. For units of length category, the other contexts available are :rainfall, :snowfall, :vehicle, :visibility and :road. Using the above example with the context of :rainfall we see
  iex> Cldr.Unit.localize height, :rainfall, territory: :US
  [#Unit<:inch, 71>]
  • Adds a :per option to Cldr.Unit.to_string/3. This option leverages the per formatting style to allow compound units to be printed. For example, assume want to emit a string which represents "kilograms per second". There is no such unit defined in CLDR (or perhaps anywhere!). But if we define the unit unit = Cldr.Unit.new(:kilogram, 20) we can then execute Cldr.Unit.to_string(unit, per: :second). Each locale defines a specific way to format such a compount unit. Usually it will return something like 20 kilograms/second

  • Adds Cldr.Unit.unit_preferences/0 to map units into a territory preference alternative unit

  • Adds Cldr.Unit.measurement_systems/0 that identifies the unit system in use for a territory

  • Adds Cldr.Unit.measurement_system_for/1 that returns the measurement system in use for a given territory. The result will be one of :metric, :US or :UK.

Cldr Unit version 2.5.3

23 Aug 01:22
Compare
Choose a tag to compare

Bug Fixes

  • Fix @spec for Cldr.Unit.to_string/3 and Cldr.Unit.to_string!/3