@@ -82,20 +82,20 @@ defmodule Date do
8282 366
8383 iex> Enum.member?(range, ~D[2001-02-01])
8484 true
85- iex> Enum.reduce(range, 0, fn( _date, acc) -> acc - 1 end)
85+ iex> Enum.reduce(range, 0, fn _date, acc -> acc - 1 end)
8686 -366
8787 """
8888
8989 @ spec range ( Calendar . date , Calendar . date ) :: Date.Range . t
9090 def range ( % { calendar: calendar } = first , % { calendar: calendar } = last ) do
91- { first_days , _ } = to_rata_die ( first )
92- { last_days , _ } = to_rata_die ( last )
91+ { first_days , _ } = to_iso_days ( first )
92+ { last_days , _ } = to_iso_days ( last )
9393
9494 % Date.Range {
9595 first: first ,
9696 last: last ,
97- first_rata_die : first_days ,
98- last_rata_die : last_days ,
97+ first_in_iso_days : first_days ,
98+ last_in_iso_days : last_days ,
9999 }
100100 end
101101
@@ -412,7 +412,7 @@ defmodule Date do
412412 end
413413 def compare ( date1 , date2 ) do
414414 if Calendar . compatible_calendars? ( date1 . calendar , date2 . calendar ) do
415- case { to_rata_die ( date1 ) , to_rata_die ( date2 ) } do
415+ case { to_iso_days ( date1 ) , to_iso_days ( date2 ) } do
416416 { first , second } when first > second -> :gt
417417 { first , second } when first < second -> :lt
418418 _ -> :eq
@@ -437,10 +437,12 @@ defmodule Date do
437437
438438 ## Examples
439439
440- Imagine someone implements `Calendar.Julian`:
440+ Imagine someone implements `Calendar.Holocene`, a calendar based on the
441+ Gregorian calendar that adds exactly 10,000 years to the current Gregorian
442+ year:
441443
442- iex> Date.convert(~D[2000-01-01], Calendar.Julian )
443- {:ok, %Date{calendar: Calendar.Julian , year: 1999 , month: 12 , day: 19 }}
444+ iex> Date.convert(~D[2000-01-01], Calendar.Holocene )
445+ {:ok, %Date{calendar: Calendar.Holocene , year: 12000 , month: 1 , day: 1 }}
444446
445447 """
446448 @ spec convert ( Calendar . date , Calendar . calendar ) :: { :ok , t } | { :error , :incompatible_calendars }
@@ -451,8 +453,8 @@ defmodule Date do
451453 if Calendar . compatible_calendars? ( calendar , target_calendar ) do
452454 result_date =
453455 date
454- |> to_rata_die ( )
455- |> from_rata_die ( target_calendar )
456+ |> to_iso_days ( )
457+ |> from_iso_days ( target_calendar )
456458 { :ok , result_date }
457459 else
458460 { :error , :incompatible_calendars }
@@ -465,10 +467,12 @@ defmodule Date do
465467
466468 ## Examples
467469
468- Imagine someone implements `Calendar.Julian`:
470+ Imagine someone implements `Calendar.Holocene`, a calendar based on the
471+ Gregorian calendar that adds exactly 10,000 years to the current Gregorian
472+ year:
469473
470- iex> Date.convert!(~D[2000-01-01], Calendar.Julian )
471- %Date{calendar: Calendar.Julian , year: 1999 , month: 12 , day: 19 }
474+ iex> Date.convert!(~D[2000-01-01], Calendar.Holocene )
475+ %Date{calendar: Calendar.Holocene , year: 12000 , month: 1 , day: 1 }
472476
473477 """
474478 @ spec convert! ( Calendar . date , Calendar . calendar ) :: t
@@ -500,8 +504,8 @@ defmodule Date do
500504 """
501505 @ spec add ( Calendar . date , integer ( ) ) :: t
502506 def add ( % { calendar: calendar } = date , days ) do
503- { rata_days , fraction } = to_rata_die ( date )
504- from_rata_die ( { rata_days + days , fraction } , calendar )
507+ { iso_days_days , fraction } = to_iso_days ( date )
508+ from_iso_days ( { iso_days_days + days , fraction } , calendar )
505509 end
506510
507511 @ doc """
@@ -525,33 +529,33 @@ defmodule Date do
525529 @ spec diff ( Calendar . date , Calendar . date ) :: integer
526530 def diff ( % { calendar: Calendar.ISO , year: year1 , month: month1 , day: day1 } ,
527531 % { calendar: Calendar.ISO , year: year2 , month: month2 , day: day2 } ) do
528- Calendar.ISO . date_to_rata_die_days ( year1 , month1 , day1 ) -
529- Calendar.ISO . date_to_rata_die_days ( year2 , month2 , day2 )
532+ Calendar.ISO . date_to_iso_days_days ( year1 , month1 , day1 ) -
533+ Calendar.ISO . date_to_iso_days_days ( year2 , month2 , day2 )
530534 end
531535
532536 def diff ( % { calendar: calendar1 } = date1 , % { calendar: calendar2 } = date2 ) do
533537 if Calendar . compatible_calendars? ( calendar1 , calendar2 ) do
534- { days1 , _ } = to_rata_die ( date1 )
535- { days2 , _ } = to_rata_die ( date2 )
538+ { days1 , _ } = to_iso_days ( date1 )
539+ { days2 , _ } = to_iso_days ( date2 )
536540 days1 - days2
537541 else
538542 raise ArgumentError , "cannot calculate the difference between #{ inspect date1 } and #{ inspect date2 } because their calendars are not compatible and thus the result would be ambiguous"
539543 end
540544 end
541545
542- defp to_rata_die ( % { calendar: Calendar.ISO , year: year , month: month , day: day } ) do
543- { Calendar.ISO . date_to_rata_die_days ( year , month , day ) , { 0 , 86400000000 } }
546+ defp to_iso_days ( % { calendar: Calendar.ISO , year: year , month: month , day: day } ) do
547+ { Calendar.ISO . date_to_iso_days_days ( year , month , day ) , { 0 , 86400000000 } }
544548 end
545- defp to_rata_die ( % { calendar: calendar , year: year , month: month , day: day } ) do
546- calendar . naive_datetime_to_rata_die ( year , month , day , 0 , 0 , 0 , { 0 , 0 } )
549+ defp to_iso_days ( % { calendar: calendar , year: year , month: month , day: day } ) do
550+ calendar . naive_datetime_to_iso_days ( year , month , day , 0 , 0 , 0 , { 0 , 0 } )
547551 end
548552
549- defp from_rata_die ( { days , _ } , Calendar.ISO ) do
550- { year , month , day } = Calendar.ISO . date_from_rata_die_days ( days )
553+ defp from_iso_days ( { days , _ } , Calendar.ISO ) do
554+ { year , month , day } = Calendar.ISO . date_from_iso_days_days ( days )
551555 % Date { year: year , month: month , day: day , calendar: Calendar.ISO }
552556 end
553- defp from_rata_die ( rata_die , target_calendar ) do
554- { year , month , day , _ , _ , _ , _ } = target_calendar . naive_datetime_from_rata_die ( rata_die )
557+ defp from_iso_days ( iso_days , target_calendar ) do
558+ { year , month , day , _ , _ , _ , _ } = target_calendar . naive_datetime_from_iso_days ( iso_days )
555559 % Date { year: year , month: month , day: day , calendar: target_calendar }
556560 end
557561
0 commit comments