@@ -82,20 +82,20 @@ defmodule Date do
82
82
366
83
83
iex> Enum.member?(range, ~D[2001-02-01])
84
84
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)
86
86
-366
87
87
"""
88
88
89
89
@ spec range ( Calendar . date , Calendar . date ) :: Date.Range . t
90
90
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 )
93
93
94
94
% Date.Range {
95
95
first: first ,
96
96
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 ,
99
99
}
100
100
end
101
101
@@ -412,7 +412,7 @@ defmodule Date do
412
412
end
413
413
def compare ( date1 , date2 ) do
414
414
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
416
416
{ first , second } when first > second -> :gt
417
417
{ first , second } when first < second -> :lt
418
418
_ -> :eq
@@ -437,10 +437,12 @@ defmodule Date do
437
437
438
438
## Examples
439
439
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:
441
443
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 }}
444
446
445
447
"""
446
448
@ spec convert ( Calendar . date , Calendar . calendar ) :: { :ok , t } | { :error , :incompatible_calendars }
@@ -451,8 +453,8 @@ defmodule Date do
451
453
if Calendar . compatible_calendars? ( calendar , target_calendar ) do
452
454
result_date =
453
455
date
454
- |> to_rata_die ( )
455
- |> from_rata_die ( target_calendar )
456
+ |> to_iso_days ( )
457
+ |> from_iso_days ( target_calendar )
456
458
{ :ok , result_date }
457
459
else
458
460
{ :error , :incompatible_calendars }
@@ -465,10 +467,12 @@ defmodule Date do
465
467
466
468
## Examples
467
469
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:
469
473
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 }
472
476
473
477
"""
474
478
@ spec convert! ( Calendar . date , Calendar . calendar ) :: t
@@ -500,8 +504,8 @@ defmodule Date do
500
504
"""
501
505
@ spec add ( Calendar . date , integer ( ) ) :: t
502
506
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 )
505
509
end
506
510
507
511
@ doc """
@@ -525,33 +529,33 @@ defmodule Date do
525
529
@ spec diff ( Calendar . date , Calendar . date ) :: integer
526
530
def diff ( % { calendar: Calendar.ISO , year: year1 , month: month1 , day: day1 } ,
527
531
% { 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 )
530
534
end
531
535
532
536
def diff ( % { calendar: calendar1 } = date1 , % { calendar: calendar2 } = date2 ) do
533
537
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 )
536
540
days1 - days2
537
541
else
538
542
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"
539
543
end
540
544
end
541
545
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 } }
544
548
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 } )
547
551
end
548
552
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 )
551
555
% Date { year: year , month: month , day: day , calendar: Calendar.ISO }
552
556
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 )
555
559
% Date { year: year , month: month , day: day , calendar: target_calendar }
556
560
end
557
561
0 commit comments