Closed mnussbaumer closed 10 months ago
Ouch, that sure doesn't look right. I'll be back at my computer in a couple of hours and will dig into this right away.
Ahhhh, the issue here is the the correct year format placeholder is y
(lower case). The format placeholder Y
is the ISO Week based year which accounts for the difference. The last few days of the Gregorian 2027 are in fact in the ISO Week year of 2028.
Using the y
symbol the return value are correct:
iex> [
...> ~U[2027-12-23 05:00:40Z],
...> ~U[2027-12-24 03:30:00Z],
...> ~U[2027-12-25 05:00:00Z],
...> ~U[2027-12-26 05:00:00Z],
...> ~U[2027-12-27 05:00:23Z],
...> ~U[2027-12-28 05:40:00Z],
...> ~U[2027-12-29 12:00:00Z],
...> ~U[2027-12-30 03:00:00Z],
...> ~U[2028-12-29 12:00:00Z],
...> ~U[2028-12-30 03:00:00Z]
...> ]
iex> |> Enum.each(fn datetime ->
...> formatted = MyApp.Cldr.DateTime.to_string!(datetime, format: "MMM d, yyyy")
...> IO.inspect(datetime: datetime, formatted: formatted)
...> end)
[datetime: ~U[2027-12-23 05:00:40Z], formatted: "Dec 23, 2027"]
[datetime: ~U[2027-12-24 03:30:00Z], formatted: "Dec 24, 2027"]
[datetime: ~U[2027-12-25 05:00:00Z], formatted: "Dec 25, 2027"]
[datetime: ~U[2027-12-26 05:00:00Z], formatted: "Dec 26, 2027"]
[datetime: ~U[2027-12-27 05:00:23Z], formatted: "Dec 27, 2027"]
[datetime: ~U[2027-12-28 05:40:00Z], formatted: "Dec 28, 2027"]
[datetime: ~U[2027-12-29 12:00:00Z], formatted: "Dec 29, 2027"]
[datetime: ~U[2027-12-30 03:00:00Z], formatted: "Dec 30, 2027"]
[datetime: ~U[2028-12-29 12:00:00Z], formatted: "Dec 29, 2028"]
[datetime: ~U[2028-12-30 03:00:00Z], formatted: "Dec 30, 2028"]
:ok
The documentation for format codes does differentiate. But it can certainly use improvement and I'll work on the over the next couple of days.
@kipcole9 thank you so much for looking into it right away.
I didn't fully understand when I read the formatting rules I just thought that the ISO one would be the most "universal" but yeah, ISOweek
the week
part should have given away it was something with specific behaviour - but because it had been working just fine for a long time and all the tests... Anyway thank you! I confirmed it works. I will update all formatting to use the yyyy
variant and also look into the documentation to see if there's any point in adding some note in the formatting table.
Happy new year!
Hi, first thanks for all the cldr packages that you maintain, they are very useful. I think I found a bug - I was getting the wrong date when formatting a date time. So all the following dates in 2027, from Dec. 27th onwards, are wrongly formatted as 2028. But other years don't seem to produce the same issues.
The following script exemplifies the issue:
When I run this I get:
The weird thing is that this only happens for, in this case, the dates starting at December 27th, and only for the year 2027. The same dates with just the year 2028, or 29, all seem to work correctly on all dates.
edit ------
It's actually interesting I think there might be some days/year durations being calculated wrong somewhere. If we change the year for 2026, then the same happens but starts only on the 28th of Dec instead of 27th, if we change the year to 2025 then it starts only on the 29th, on 2024 only on the 30th, and 2023 doesn't.
-------------
I haven't got much experience with this library nor dates/calendars/dates formatting, nor how it arrives at the formatting but I was able to confirm that up to
Cldr.DateTime.to_string
it all is fine in terms of params and it is in the lastformat_backend.format
that the wrong transformation occurs, adding some IO.inspects to the ex_cldr.datetime deps resulted in this:So the date time at this calling point is correct, but the formatted version of it is 2028 instead of 2027. Hope this helps figuring it out when you have the time and patience, happy holidays,
Additional Info: