Skip to content

Commit 2e7f803

Browse files
committed
Update verison and changelog
1 parent 550ae56 commit 2e7f803

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
**Note that `ex_cldr_calendars` version 1.24.0 and later are supported on Elixir 1.12 and later only.**
44

5+
## Cldr.Calendars v2.1.1
6+
7+
This is the changelog for Cldr Calendars v2.1.1 released on March 19th, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_calendars/tags)
8+
9+
### Bug Fixes
10+
11+
* Fix `Cldr.Calendar.localize/2` for calendars that aren't derived from `Cldr.Calendar.Gregorian`. For example `Cldr.Calendar.Ethiopian`, `Cldr.Calendar.Coptic`, `Cldr.Calendar.Julian` and the lunisolar calendars.
12+
513
## Cldr.Calendars v2.1.0
614

715
This is the changelog for Cldr Calendars v2.1.0 released on March 18th, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_calendars/tags)

lib/cldr/calendar.ex

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ defmodule Cldr.Calendar do
292292
in this implementation.
293293
"""
294294
@callback cldr_calendar_type() ::
295-
:gregorian | :persian | :coptic | :ethiopic | :chinese | :japanese | :dangi
295+
:gregorian | :persian | :coptic | :ethiopic |
296+
:ethiopic_amete_alem | :chinese | :japanese | :dangi
296297

297298
@doc """
298299
Returns the calendar basis.
@@ -1280,7 +1281,9 @@ defmodule Cldr.Calendar do
12801281
@spec iso_day_of_week(date()) :: Calendar.day_of_week()
12811282

12821283
def iso_day_of_week(date) do
1283-
Date.day_of_week(date, :monday)
1284+
date
1285+
|> Date.convert!(Calendar.ISO)
1286+
|> Date.day_of_week(:monday)
12841287
end
12851288

12861289
@doc """
@@ -2679,10 +2682,9 @@ defmodule Cldr.Calendar do
26792682

26802683
with {_, era} <- day_of_era(datetime) do
26812684
era_key = if variant?, do: -era - 1, else: era
2685+
eras = backend.eras(locale, calendar.cldr_calendar_type())
26822686

2683-
locale
2684-
|> backend.eras(calendar.cldr_calendar_type())
2685-
|> get_in([format, era_key])
2687+
get_in(eras, [format, era_key])
26862688
end
26872689
end
26882690

@@ -2753,15 +2755,15 @@ defmodule Cldr.Calendar do
27532755
case month_of_year(datetime) do
27542756
month when is_number(month) ->
27552757
cardinal_month =
2756-
cardinal_month(month, calendar.__config__(), months_in_year)
2758+
cardinal_month(month, calendar, months_in_year)
27572759

27582760
locale
27592761
|> backend.months(calendar.cldr_calendar_type())
27602762
|> get_in([type, format, cardinal_month])
27612763

27622764
{month, :leap} when is_number(month) ->
27632765
cardinal_month =
2764-
cardinal_month(month, calendar.__config__(), months_in_year)
2766+
cardinal_month(month, calendar, months_in_year)
27652767

27662768
month_patterns =
27672769
backend.month_patterns(locale, calendar.cldr_calendar_type())
@@ -2853,22 +2855,38 @@ defmodule Cldr.Calendar do
28532855
# Get the month of the calendar-specific year as the month
28542856
# in the gregorian calendar (starting in January)
28552857
@doc false
2856-
def cardinal_month(month, %{month_of_year: 1}, _months_in_year) do
2858+
def cardinal_month(month, calendar, months_in_year) do
2859+
if function_exported?(calendar, :__config__, 0) do
2860+
do_cardinal_month(month, calendar.__config__(), months_in_year)
2861+
else
2862+
month
2863+
end
2864+
end
2865+
2866+
defp do_cardinal_month(month, %{month_of_year: 1}, _months_in_year) do
28572867
month
28582868
end
28592869

2860-
def cardinal_month(month, %{month_of_year: month_of_year}, months_in_year) do
2870+
defp do_cardinal_month(month, %{month_of_year: month_of_year}, months_in_year) do
28612871
Cldr.Math.amod(month + month_of_year - 1, months_in_year)
28622872
end
28632873

28642874
# Get the calendar-specific day of the week as the day
28652875
# of the week in Calendar.ISO which starts with 1 == Monday.
28662876
@doc false
2867-
def cardinal_day_of_week(day, %{day_of_week: 1}) do
2877+
def cardinal_day_of_week(day, calendar) do
2878+
if function_exported?(calendar, :__config__, 0) do
2879+
do_cardinal_day_of_week(day, calendar.__config__())
2880+
else
2881+
day
2882+
end
2883+
end
2884+
2885+
def do_cardinal_day_of_week(day, %{day_of_week: 1}) do
28682886
day
28692887
end
28702888

2871-
def cardinal_day_of_week(day, %{day_of_week: day_of_week}) do
2889+
def do_cardinal_day_of_week(day, %{day_of_week: day_of_week}) do
28722890
Cldr.Math.amod(day + day_of_week - 1, @days_in_a_week)
28732891
end
28742892

lib/cldr/calendar/backend/calendar.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ defmodule Cldr.Calendar.Backend do
1515
`Cldr` defines formats for several calendars, the names of which
1616
are returned by `Cldr.known_calendars/0`.
1717
18-
Currently this implementation only supports the `:gregorian`,
19-
`:persian`, `:coptic` and `ethiopic` calendars.
18+
Currently this implementation supports the `:gregorian`,
19+
`:persian`, `:coptic`, `:ethiopic`, `:ethiopic_amete_alem`, `:japanese`,
20+
`:chinese`` and `:dangi` calendars.
2021
2122
The `:gregorian` calendar aligns with the proleptic Gregorian calendar
2223
defined by Elixir, `Calendar.ISO`.
@@ -39,6 +40,7 @@ defmodule Cldr.Calendar.Backend do
3940
:persian,
4041
:coptic,
4142
:ethiopic,
43+
:ethiopic_amete_alem,
4244
:chinese,
4345
:japanese,
4446
:dangi
@@ -352,28 +354,28 @@ defmodule Cldr.Calendar.Backend do
352354
end,
353355
month_names: fn month ->
354356
cardinal_month =
355-
Cldr.Calendar.cardinal_month(month, calendar_config, 12)
357+
Cldr.Calendar.cardinal_month(month, calendar, 12)
356358

357359
months(locale, cldr_calendar)
358360
|> get_in([:format, :wide, cardinal_month])
359361
end,
360362
abbreviated_month_names: fn month ->
361363
cardinal_month =
362-
Cldr.Calendar.cardinal_month(month, calendar_config, 12)
364+
Cldr.Calendar.cardinal_month(month, calendar, 12)
363365

364366
months(locale, cldr_calendar)
365367
|> get_in([:format, :abbreviated, cardinal_month])
366368
end,
367369
day_of_week_names: fn day ->
368370
cardinal_day_of_week =
369-
Cldr.Calendar.cardinal_day_of_week(day, calendar_config)
371+
Cldr.Calendar.cardinal_day_of_week(day, calendar)
370372

371373
days(locale, cldr_calendar)
372374
|> get_in([:format, :wide, cardinal_day_of_week])
373375
end,
374376
abbreviated_day_of_week_names: fn day ->
375377
cardinal_day_of_week =
376-
Cldr.Calendar.cardinal_day_of_week(day, calendar_config)
378+
Cldr.Calendar.cardinal_day_of_week(day, calendar)
377379

378380
days(locale, cldr_calendar)
379381
|> get_in([:format, :abbreviated, cardinal_day_of_week])

lib/cldr/calendar/era.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ defmodule Cldr.Calendar.Era do
8383
@eras_in_julian_calendar [
8484
:coptic,
8585
:ethiopic,
86+
:ethiopic_amete_alem,
8687
:islamic,
8788
:islamic_civil,
8889
:islamic_rgsa,

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Cldr.Calendar.MixProject do
22
use Mix.Project
33

4-
@version "2.1.0"
4+
@version "2.1.1"
55

66
def project do
77
[

0 commit comments

Comments
 (0)