diff --git a/CHANGELOG.md b/CHANGELOG.md index 2735c83..49e7967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ **Note that `ex_cldr_dates_times` version 2.14.0 and later are supported on Elixir 1.11 and later only.** +## Cldr_Dates_Times v2.15.1 + +This is the changelog for Cldr_Dates_Times v2.15.1 released on October 22nd, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags) + +### Bug Fixes + +* Fix formatting time intervals when the `to` time is not greater than the `from` time. This allows time intervals that cross midnight to be formatted correctly. Thanks to @larshei for the report. Closes #42. + ## Cldr_Dates_Times v2.15.0 This is the changelog for Cldr_Dates_Times v2.15.0 released on October 17th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags) diff --git a/lib/cldr/interval/time.ex b/lib/cldr/interval/time.ex index 49c1a3f..da19bae 100644 --- a/lib/cldr/interval/time.ex +++ b/lib/cldr/interval/time.ex @@ -246,8 +246,7 @@ defmodule Cldr.Time.Interval do |> Keyword.put(:locale, locale) |> Keyword.put(:number_system, number_system) - with {:ok, _} <- from_less_than_or_equal_to(from, to), - {:ok, backend} <- Cldr.validate_backend(backend), + with {:ok, backend} <- Cldr.validate_backend(backend), {:ok, locale} <- Cldr.validate_locale(locale, backend), {:ok, _} <- Cldr.Number.validate_number_system(locale, number_system, backend), {:ok, calendar} <- Cldr.Calendar.validate_calendar(from.calendar), @@ -313,8 +312,7 @@ defmodule Cldr.Time.Interval do `Calendar.time` type. * `to` is any map that conforms to the - `Calendar.time` type. `to` must occur - on or after `from`. + `Calendar.time` type. * `backend` is any module that includes `use Cldr` and is therefore `Cldr` backend module @@ -368,6 +366,9 @@ defmodule Cldr.Time.Interval do iex> Cldr.Time.Interval.to_string! ~T[10:00:00], ~T[10:03:00], MyApp.Cldr, format: :long "10:00 – 10:03 AM" + iex> Cldr.Time.Interval.to_string ~T[23:00:00.0Z], ~T[01:01:00.0Z], MyApp.Cldr + {:ok, "11:00 PM – 1:01 AM"} + iex> Cldr.Time.Interval.to_string! ~T[10:00:00], ~T[10:03:00], MyApp.Cldr, ...> format: :long, style: :flex "10:00 – 10:03 in the morning" @@ -427,12 +428,12 @@ defmodule Cldr.Time.Interval do Cldr.Date.Interval.greatest_difference(from, to) end - defp from_less_than_or_equal_to(from, to) do - case Time.compare(from, to) do - comp when comp in [:eq, :lt] -> {:ok, comp} - _other -> {:error, Cldr.Date.Interval.datetime_order_error(from, to)} - end - end + # defp from_less_than_or_equal_to(from, to) do + # case Time.compare(from, to) do + # comp when comp in [:eq, :lt] -> {:ok, comp} + # _other -> {:error, Cldr.Date.Interval.datetime_order_error(from, to)} + # end + # end defp resolve_format(from, to, formats, locale, options) do format = Keyword.get(options, :format, @default_format) @@ -450,7 +451,7 @@ defmodule Cldr.Time.Interval do end defp greatest_difference_format(%{hour: from}, %{hour: to}, format, :H) - when from < 12 and to >= 12 do + when (from < 12 and to >= 12) or (from >= 12 and to < 12) do case Map.get(format, :b) || Map.get(format, :a) || Map.get(format, :H) || Map.get(format, :h) do nil -> {:error, format_error(format, format)} success -> {:ok, success} diff --git a/mix.exs b/mix.exs index c3e6271..4454942 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Cldr.DatesTimes.Mixfile do use Mix.Project - @version "2.15.0" + @version "2.15.1" def project do [