elixir-cldr / cldr_dates_times

Date & times formatting functions for the Common Locale Data Repository (CLDR) package https://github.com/elixir-cldr/cldr
Other
68 stars 13 forks source link

no function clause matching in Cldr.DateTime.Relative.scale_relative/2 #26

Closed maennchen closed 3 years ago

maennchen commented 3 years ago

There seems to be a new bug introduced in c5f6d309ef271a2c4b7e6c003735f7204a3bd29c

When running the following code, an error is produced:

        Cldr.DateTime.Relative.to_string!(@time,
          format: :short,
          relative_to: @now
        )

Both @time and @now are normal DateTimes.

[error] GenServer #PID<0.1360.0> terminating
** (FunctionClauseError) no function clause matching in Cldr.DateTime.Relative.scale_relative/2
    (ex_cldr_dates_times 2.9.3) lib/cldr/datetime/relative.ex:379: Cldr.DateTime.Relative.scale_relative(-91042, ~U[2021-09-21 08:05:46.404457Z])
    (ex_cldr_dates_times 2.9.3) lib/cldr/datetime/relative.ex:177: Cldr.DateTime.Relative.define_unit_and_relative_time/3
    (ex_cldr_dates_times 2.9.3) lib/cldr/datetime/relative.ex:142: Cldr.DateTime.Relative.to_string/3
    (ex_cldr_dates_times 2.9.3) lib/cldr/datetime/relative.ex:256: Cldr.DateTime.Relative.to_string!/3
    (hygeia_web 0.0.0-noversion) lib/hygeia_web/live/relative_time.ex:28: anonymous fn/3 in HygeiaWeb.RelativeTime.render/1

https://github.com/jshmrtn/hygeia/blob/4d4e23b24ddb0c19daee3cf13529033de7856177/apps/hygeia_web/lib/hygeia_web/live/relative_time.ex#L28

kipcole9 commented 3 years ago

I'm am really sorry to see that, even more so that the resolution doesn't immediately jump out. I'm seeing:

iex> now = DateTime.utc_now
~U[2021-09-22 09:36:50.220795Z]
iex(2)> then = DateTime.utc_now
~U[2021-09-22 09:37:02.547976Z]
iex> Cldr.DateTime.Relative.to_string then, relative_to: now
{:ok, "in 12 seconds"}
iex> Cldr.DateTime.Relative.to_string then, relative_to: now, format: :short
{:ok, "in 12 sec."}

Meaning I'll have to dig deeper - starting now.

maennchen commented 3 years ago

@kipcole9 I'll provide some more details then like the specific dates.

This is our Cldr Module: https://github.com/jshmrtn/hygeia/blob/master/apps/hygeia_cldr/lib/hygeia_cldr.ex

No need to be sorry, thanks as always for having a look :)

kipcole9 commented 3 years ago

OK, got it. Just adding tests and will publish again.

kipcole9 commented 3 years ago

Published ex_cldr_dates_times version 2.9.4 with the following changelog entry:

Bug fixes

maennchen commented 3 years ago

@kipcole9 I'll test in a minute, thank you so much for fixing this that fast :heart: