11defmodule Cldr.Calendar.Julian.Compiler do
2+ # See https://stevemorse.org/jcal/julian.html
23
34 defmacro __before_compile__ ( env ) do
45 opts =
@@ -21,6 +22,13 @@ defmodule Cldr.Calendar.Julian.Compiler do
2122
2223 defguard year_rollover ( month , day ) when month <= @ new_year_starting_month and day < @ new_year_starting_day
2324
25+ # Adjust the year to be a Jan 1st starting year and carry
26+ # on
27+
28+ def date_to_iso_days ( year , month , day ) when year_rollover ( month , day ) do
29+ Cldr.Calendar.Julian . date_to_iso_days ( year + 1 , month , day )
30+ end
31+
2432 def date_to_iso_days ( year , month , day ) do
2533 Cldr.Calendar.Julian . date_to_iso_days ( year , month , day )
2634 end
@@ -34,12 +42,17 @@ defmodule Cldr.Calendar.Julian.Compiler do
3442 { year , month , day } = Cldr.Calendar.Julian . date_from_iso_days ( iso_days )
3543
3644 if month <= @ new_year_starting_month and day < @ new_year_starting_day do
37- { year + 1 , month , day }
45+ { year - 1 , month , day }
3846 else
3947 { year , month , day }
4048 end
4149 end
4250
51+ def naive_datetime_from_iso_days ( { iso_days , _ } ) do
52+ { year , month , day } = date_from_iso_days ( iso_days )
53+ { year , month , day , 0 , 0 , 0 , { 0 , 0 } }
54+ end
55+
4356 def days_in_year ( year ) do
4457 first_day = date_to_iso_days ( year , @ new_year_starting_month , @ new_year_starting_day )
4558 first_day_next_year = date_to_iso_days ( year + 1 , @ new_year_starting_month , @ new_year_starting_day )
@@ -195,7 +208,6 @@ defmodule Cldr.Calendar.Julian.Compiler do
195208 defdelegate shift_naive_datetime ( year , month , day , hour , minute , second , millisecond , duration ) , to: Cldr.Calendar.Julian
196209 defdelegate iso_days_to_end_of_day ( iso_days ) , to: Cldr.Calendar.Julian
197210 defdelegate iso_days_to_beginning_of_day ( iso_days ) , to: Cldr.Calendar.Julian
198- defdelegate naive_datetime_from_iso_days ( iso_days ) , to: Cldr.Calendar.Julian
199211 defdelegate parse_utc_datetime ( string ) , to: Cldr.Calendar.Julian
200212 defdelegate parse_time ( string ) , to: Cldr.Calendar.Julian
201213 defdelegate parse_naive_datetime ( string ) , to: Cldr.Calendar.Julian
0 commit comments