diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d018cb..9d39e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ **Note that `ex_cldr_dates_times` version 2.18.0 and later are supported on Elixir 1.12 and later only.** +## Cldr_Dates_Times v2.20.3 + +This is the changelog for Cldr_Dates_Times v2.20.3 released on August 17th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_cldr_dates_times/tags) + +### Bug Fixes + +* Fix specs to pass with a broader range of dialyzer options. + ## Cldr_Dates_Times v2.20.2 This is the changelog for Cldr_Dates_Times v2.20.2 released on August 3rd, 2024. 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/backend/format.ex b/lib/cldr/backend/format.ex index bfaaa25..d72a71f 100644 --- a/lib/cldr/backend/format.ex +++ b/lib/cldr/backend/format.ex @@ -377,7 +377,9 @@ defmodule Cldr.DateTime.Format.Backend do }} """ - @spec date_time_available_formats(Locale.locale_reference(), calendar) :: {:ok, formats} + @spec date_time_available_formats(Locale.locale_reference(), calendar) :: + {:ok, formats} | {:error, {module, String.t()}} + def date_time_available_formats( locale \\ unquote(backend).get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar() @@ -413,7 +415,9 @@ defmodule Cldr.DateTime.Format.Backend do iex> #{inspect(__MODULE__)}.date_available_formats "en" """ - @spec date_available_formats(Locale.locale_reference(), calendar) :: {:ok, formats} + @spec date_available_formats(Locale.locale_reference(), calendar) :: + {:ok, formats} | {:error, {module, String.t()}} + def date_available_formats( locale \\ unquote(backend).get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar() @@ -449,7 +453,9 @@ defmodule Cldr.DateTime.Format.Backend do iex> #{inspect(__MODULE__)}.time_available_formats :en """ - @spec time_available_formats(Locale.locale_reference(), calendar) :: {:ok, formats} + @spec time_available_formats(Locale.locale_reference(), calendar) :: + {:ok, formats} | {:error, {module, String.t()}} + def time_available_formats( locale \\ unquote(backend).get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar() @@ -599,7 +605,8 @@ defmodule Cldr.DateTime.Format.Backend do """ @spec date_time_interval_formats(Locale.locale_reference(), calendar()) :: - {:ok, formats} + {:ok, formats} | {:error, {module, String.t()}} + def date_time_interval_formats( locale \\ unquote(backend).get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar() @@ -693,7 +700,9 @@ defmodule Cldr.DateTime.Format.Backend do {:ok, {"+HH:mm", "-HH:mm"}} """ - @spec hour_format(Locale.locale_reference()) :: {:ok, {String.t(), String.t()}} + @spec hour_format(Locale.locale_reference()) :: + {:ok, {String.t(), String.t()}} | {:error, {module, String.t()}} + def hour_format(locale \\ unquote(backend).get_locale()) def hour_format(%LanguageTag{cldr_locale_name: cldr_locale_name}) do @@ -721,7 +730,9 @@ defmodule Cldr.DateTime.Format.Backend do {:ok, ["GMT", 0]} """ - @spec gmt_format(Locale.locale_reference()) :: {:ok, [non_neg_integer | String.t(), ...]} + @spec gmt_format(Locale.locale_reference()) :: + {:ok, [non_neg_integer | String.t(), ...]} | {:error, {module, String.t()}} + def gmt_format(locale \\ unquote(backend).get_locale()) def gmt_format(%LanguageTag{cldr_locale_name: cldr_locale_name}) do @@ -1001,7 +1012,8 @@ defmodule Cldr.DateTime.Format.Backend do Elixir.Calendar.time(), LanguageTag.t() | String.t() | Locale.locale_name() ) :: - atom + atom | {:error, {module, String.t()}} + def day_period_for(time, language) def day_period_for(time, %LanguageTag{language: language}) do @@ -1030,7 +1042,8 @@ defmodule Cldr.DateTime.Format.Backend do """ @spec language_has_noon_and_midnight?(LanguageTag.t() | String.t() | Locale.locale_name()) :: - boolean + boolean | {:error, {module, String.t()}} + def language_has_noon_and_midnight?(locale) def language_has_noon_and_midnight?(%LanguageTag{language: language}) do diff --git a/lib/cldr/format/date_time_formatter.ex b/lib/cldr/format/date_time_formatter.ex index 4314dcf..fb17dd6 100644 --- a/lib/cldr/format/date_time_formatter.ex +++ b/lib/cldr/format/date_time_formatter.ex @@ -170,7 +170,7 @@ defmodule Cldr.DateTime.Formatter do """ @spec date(Calendar.date(), integer, Keyword.t()) :: - String.t() | {:error, String.t()} + String.t() | {:error, String.t()} | {:error, {module, String.t()}} def date(date, n \\ @default_format, options \\ []) @@ -234,7 +234,7 @@ defmodule Cldr.DateTime.Formatter do Cldr.backend(), Keyword.t() | map() ) :: - String.t() | {:error, String.t()} + String.t() | {:error, String.t()} | {:error, {module, String.t()}} def time(time, _n, _locale, backend, options) when is_list(options) do with {:ok, time_string} <- Cldr.Time.to_string(time, backend, options) do @@ -3897,6 +3897,7 @@ defmodule Cldr.DateTime.Formatter do defp number_of_digits(n), do: Enum.count(Integer.digits(n)) @doc false + @dialyzer {:nowarn_function, error_return: 3} def error_return(map, symbol, requirements) do requirements = requirements @@ -3905,6 +3906,8 @@ defmodule Cldr.DateTime.Formatter do raise Cldr.DateTime.FormatError, "The format symbol '#{symbol}' requires at map with at least #{requirements}. Found: #{inspect(map)}" + + :error end @doc false diff --git a/mix.exs b/mix.exs index 9cd3e92..e607865 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Cldr.DatesTimes.Mixfile do use Mix.Project - @version "2.20.2" + @version "2.20.3" def project do [ @@ -20,7 +20,13 @@ defmodule Cldr.DatesTimes.Mixfile do dialyzer: [ ignore_warnings: ".dialyzer_ignore_warnings", plt_add_apps: ~w(calendar_interval)a, - flags: [:underspecs] + flags: [ + :error_handling, + :unknown, + :underspecs, + :extra_return, + :missing_return + ] ], xref: [exclude: [:eprof]] ] @@ -72,6 +78,7 @@ defmodule Cldr.DatesTimes.Mixfile do [ {:ex_cldr, "~> 2.40"}, {:ex_cldr_calendars, "~> 1.25"}, + {:calendar_interval, "~> 0.2", optional: true}, {:ex_cldr_units, "~> 3.17", optional: true}, {:ex_doc, "~> 0.25", optional: true, only: [:dev, :release], runtime: false}, diff --git a/mix.lock b/mix.lock index 7774039..6c3d169 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ %{ "benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"}, "calendar_interval": {:hex, :calendar_interval, "0.2.0", "2b253b1e37ee1d4344639a3cbfb12abd0e996e4a8181537eb33c3e93fdfaffd9", [:mix], [], "hexpm", "c13d5e0108e61808a38f622987e1c5e881d96d28945213d3efe6dd06c28ba7b0"}, - "cldr_utils": {:hex, :cldr_utils, "2.28.0", "ce309d11b79fc13e1f22f808b5e3c1647102b01b11734ca8cb0296ca6d406fe4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "e7ac4bcea0fdbc11b5295ef30dd7b18d0922512399361af06a97198e57d23742"}, + "cldr_utils": {:hex, :cldr_utils, "2.28.1", "3d85c835e1d0b7bceb9feed1647025ff7df59180246f13b582422f12b1afd52c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "79a5f645481d09b1372962384aa275d67d69273e73e3b38a9fee363eb57c2b79"}, "coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, @@ -10,12 +10,12 @@ "earmark": {:hex, :earmark, "1.4.14", "d04572cef64dd92726a97d92d714e38d6e130b024ea1b3f8a56e7de66ec04e50", [:mix], [{:earmark_parser, ">= 1.4.12", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "df338b8b1852ee425180b276c56c6941cb12220e04fe8718fe4acbdd35fd699f"}, "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, - "ex_cldr": {:hex, :ex_cldr, "2.40.0", "624717778dbf0a8cd307f1576eabbd44470c16190172abf293fed24150440a5a", [:mix], [{:cldr_utils, "~> 2.28", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "113394b6dd23aaf7912da583aab103d9cf082b9821bc4a6e287543a895af7cb4"}, - "ex_cldr_calendars": {:hex, :ex_cldr_calendars, "1.26.0", "d832996d30360ad68475b57da02ce1adbc5609459d89b779f9148f34cce09469", [:mix], [{:calendar_interval, "~> 0.2", [hex: :calendar_interval, repo: "hexpm", optional: true]}, {:ex_cldr_lists, "~> 2.10", [hex: :ex_cldr_lists, repo: "hexpm", optional: true]}, {:ex_cldr_numbers, "~> 2.31", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_cldr_units, "~> 3.16", [hex: :ex_cldr_units, repo: "hexpm", optional: true]}, {:ex_doc, "~> 0.21", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "6ace2824ae10c3f456714f031a5de168da05253baf9119582c87b2daa823af46"}, + "ex_cldr": {:hex, :ex_cldr, "2.40.1", "c1fcb0cd9d2a70d28f4540a99f32127e7f1813e0db109d65ab29dea5337ae266", [:mix], [{:cldr_utils, "~> 2.28", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "509810702e8e81991851d9426ffe6b34b48b7b9baa12922e7b3fb8f6368606f3"}, + "ex_cldr_calendars": {:hex, :ex_cldr_calendars, "1.26.1", "b9abb56a3443edf77e3180f4d45f7d18748d5a7f9fbe8f464cc33a6dcf253ea8", [:mix], [{:calendar_interval, "~> 0.2", [hex: :calendar_interval, repo: "hexpm", optional: true]}, {:ex_cldr_lists, "~> 2.10", [hex: :ex_cldr_lists, repo: "hexpm", optional: true]}, {:ex_cldr_numbers, "~> 2.31", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_cldr_units, "~> 3.16", [hex: :ex_cldr_units, repo: "hexpm", optional: true]}, {:ex_doc, "~> 0.21", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f11a1981231e57cd07f76f6d90bb69a88251140a37cfbb9cb33f2051f7c15423"}, "ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.16.2", "670d96cc4fb18cfebd82488ed687742683be2d0725d66ec051578d4b13539aa8", [:mix], [{:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "2ccfac2838f4df8c8e5424dbc68eb2f3ac9eeb45e10365050901f7ac7a914ce1"}, - "ex_cldr_lists": {:hex, :ex_cldr_lists, "2.11.0", "1d39e75f0e493ccc95adfc85c55b4ca34f0771626350ce326d9ab8813d91444e", [:mix], [{:ex_cldr_numbers, "~> 2.25", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "8132b30a5506ae8a09e5c9a21c23fd60c8837ce6c3a1de9966d813eb78951695"}, - "ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.33.2", "c5587a8d84214d9cc42e7827e4c3bed2aa9e52505a55b10540020725954ded2c", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.16", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "49f1dbaddc1ad6e3f496a97fa425d25b3ae89e8178ce0416d9909deaf2e5ad80"}, - "ex_cldr_units": {:hex, :ex_cldr_units, "3.17.1", "f03c7a138113511af903d0d2205b5cc01df1e599c28839ca2e1e78b7ca0bf2a2", [:mix], [{:cldr_utils, "~> 2.25", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr_lists, "~> 2.10", [hex: :ex_cldr_lists, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.33.0", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "7de1bf7ff7599cf4da9dd0f1a7b6e19ca8db83b883301f5dcd0f565aa5eaec8c"}, + "ex_cldr_lists": {:hex, :ex_cldr_lists, "2.11.1", "ad18f861d7c5ca82aac6d173469c6a2339645c96790172ab0aa255b64fb7303b", [:mix], [{:ex_cldr_numbers, "~> 2.25", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "00161c04510ccb3f18b19a6b8562e50c21f1e9c15b8ff4c934bea5aad0b4ade2"}, + "ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.33.3", "9fedcf279a17d19abdf8872738472326e82378d90ec2dd9756a0c84558c86b36", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.16", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4a0d90d06710c1499528d5f536c539379a73a68d4679c55375198a798d138442"}, + "ex_cldr_units": {:hex, :ex_cldr_units, "3.17.2", "b0483d5c61c6c8649aafdcafc7372dd71a7a30f52dd4c9b072576467bf721454", [:mix], [{:cldr_utils, "~> 2.25", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr_lists, "~> 2.10", [hex: :ex_cldr_lists, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.33.0", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "457d76c6e3b548bd7aba3c7b5d157213be2842d1162c2283abf81d9e2f1e1fc7"}, "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, "exprintf": {:hex, :exprintf, "0.2.1", "b7e895dfb00520cfb7fc1671303b63b37dc3897c59be7cbf1ae62f766a8a0314", [:mix], [], "hexpm", "20a0e8c880be90e56a77fcc82533c5d60c643915c7ce0cc8aa1e06ed6001da28"}, "exprof": {:hex, :exprof, "0.2.4", "13ddc0575a6d24b52e7c6809d2a46e9ad63a4dd179628698cdbb6c1f6e497c98", [:mix], [{:exprintf, "~> 0.2", [hex: :exprintf, repo: "hexpm", optional: false]}], "hexpm", "0884bcb66afc421c75d749156acbb99034cc7db6d3b116c32e36f32551106957"}, diff --git a/mix/for_dialyzer.ex b/mix/for_dialyzer.ex index dfcc9c5..86b876f 100644 --- a/mix/for_dialyzer.ex +++ b/mix/for_dialyzer.ex @@ -68,4 +68,16 @@ defmodule Cldr.DatesTimes.Dialyzer do _ = Cldr.DateTime.Format.common_date_time_format_names() end + + def other_tests do + datetime = DateTime.utc_now() + Process.sleep(3000) + + _ = + datetime + |> DateTime.diff(DateTime.utc_now(), :second) + |> MyApp.Cldr.DateTime.Relative.to_string!() + + _ = MyApp.Cldr.DateTime.to_string!(datetime, []) + end end