Closed matt-glover closed 1 year ago
Matt, thanks for the kind words. Time is hard! I understand what you're trying to do. Let me think on it a bit today (UTC+11) and see what can be done.
Matt, I've pushed a commit which I believe does what you expect. Already the code will fallback to "greatest difference :year" from the greatest difference month and day if those formats don't exist. So it's reasonable that greatest difference :year
should also try month and day formats if a year format doesn't exist.
Would you considering configuring ex_cldr_dates_times
from GitHub and let me know if it works for your requirements?
With this commit the code now does the following:
defp greatest_difference_format(format, requested_format, requested_style, :y = difference) do
resolved_format = Map.get(format, difference) || Map.get(format, :M) || Map.get(format, :d) || :error
case resolved_format do
:error -> {:error, unavailable_format_error(requested_format, requested_style, difference)}
success -> {:ok, success}
end
end
I also improved the error message if there is no resolvable format (it wasn't a very good one before).
Lastly, I did a proof read of the various Interval modules to make them a bit better.
Let me know if this now works as you expect - and of course re-open if not. I will publish to Hex an update when you say it's ok for you.
I’ll take a look Monday (UTC-4) when I get in to work to be sure. But glancing at the PR I’m pretty sure the change is exactly what I need.
That change is producing the expected output for me. I had to update various other CLDR dependencies and I'm getting plenty of other test failures I have to work through where we asserted on CLDR output already. But I get those failures with the latest ex_cldr*
packages including the latest released version of this package. I suspect my issues are tied to CLDR 43 which we weren't using yet. Seeing a mix of no longer valid formats + changes around the type of space or hyphen/dash/etc being used to delimit things. So I'll be debugging those before I can cut over to this latest version. But the fix looks good to me.
Thanks for all the help!
Yes, CLDR 43 did change quite a bit of white space in formats. A pain for updating tests I agree, but a better longer-term outcome.
I've published ex_cldr_dates_times version 2.14.3 with the following changelog entry:
:month_and_day
style when the last date is in a different year to the first. Thanks to @matt-glover for the report. Closes #40.
Hi,
First off thanks for the work on this great library!
I have some code to display date intervals using this library and leveraging the
short
format with themonth_and_day
style. I discovered that this returns an error whenever the date range crosses a year boundary. For example:I can see why/how this triggers (explained below). But my core question is whether I should treat this as a special case and handle it myself using a different format/custom logic or if I should consider this a bug somewhere in the Elixir CLDR stack and try to issue a patch.
I dug into the formatting rules and saw that
short
format andmonth_and_day
style give meMd
. In the default "en" locale with a default Gregorian calendar I getMd: %{d: ["M/d – ", "M/d"], M: ["M/d – ", "M/d"]},
. The greatest difference check for date intervals spits outy
(year) as the difference here and then obviously lacking ay
option in theMd
map it tells me the interval format is invalid.I hoped to stick with the shortcut options like
short
andlong
to get support out-of-the-box for various locales. Seems like that might work okay here if I ditched thestyle
parameter?I'm a little out of my depth so I paused here before identifying whether the
Md
mapping is from the Unicode CLDR project itself vs something in one of the suite of Elixir libraries involved. Any advice is appreciated.