@@ -69,11 +69,6 @@ defmodule Date do
6969 calendar: Calendar . calendar ( )
7070 }
7171
72- @ typedoc "A duration unit expressed as a tuple."
73- @ typedoc since: "1.19.0"
74- @ type duration_unit_pair ::
75- { :year , integer } | { :month , integer } | { :week , integer } | { :day , integer }
76-
7772 @ doc """
7873 Returns a range of dates.
7974
@@ -89,20 +84,6 @@ defmodule Date do
8984 iex> Date.range(~D[1999-01-01], ~D[2000-01-01])
9085 Date.range(~D[1999-01-01], ~D[2000-01-01])
9186
92- A range may also be built from a `Date` and a `Duration`
93- (also expressed as a keyword list of `t:duration_unit_pair/0`):
94-
95- iex> Date.range(~D[1999-01-01], Duration.new!(year: 1))
96- Date.range(~D[1999-01-01], ~D[2000-01-01])
97- iex> Date.range(~D[1999-01-01], year: 1)
98- Date.range(~D[1999-01-01], ~D[2000-01-01])
99-
100- > #### Durations {: .warning}
101- >
102- > Support for expressing `last` as a [`Duration`](`t:Duration.t/0`) or
103- > keyword list of `t:duration_unit_pair/0`s was introduced in
104- > v1.19.0.
105-
10687 A range of dates implements the `Enumerable` protocol, which means
10788 functions in the `Enum` module can be used to work with
10889 ranges:
@@ -119,11 +100,7 @@ defmodule Date do
119100
120101 """
121102 @ doc since: "1.5.0"
122- @ spec range (
123- first :: Calendar . date ( ) ,
124- last_or_duration :: Calendar . date ( ) | Duration . t ( ) | [ duration_unit_pair ]
125- ) ::
126- Date.Range . t ( )
103+ @ spec range ( Calendar . date ( ) , Calendar . date ( ) ) :: Date.Range . t ( )
127104 def range ( % { calendar: calendar } = first , % { calendar: calendar } = last ) do
128105 { first_days , _ } = to_iso_days ( first )
129106 { last_days , _ } = to_iso_days ( last )
@@ -146,16 +123,6 @@ defmodule Date do
146123 raise ArgumentError , "both dates must have matching calendars"
147124 end
148125
149- def range ( % { calendar: _ } = first , % Duration { } = duration ) do
150- last = shift ( first , duration )
151- range ( first , last )
152- end
153-
154- def range ( % { calendar: _ } = first , duration ) when is_list ( duration ) do
155- last = shift ( first , duration )
156- range ( first , last )
157- end
158-
159126 @ doc """
160127 Returns a range of dates with a step.
161128
@@ -173,11 +140,8 @@ defmodule Date do
173140
174141 """
175142 @ doc since: "1.12.0"
176- @ spec range (
177- first :: Calendar . date ( ) ,
178- last_or_duration :: Calendar . date ( ) | Duration . t ( ) | [ duration_unit_pair ] ,
179- step :: pos_integer | neg_integer
180- ) :: Date.Range . t ( )
143+ @ spec range ( Calendar . date ( ) , Calendar . date ( ) , step :: pos_integer | neg_integer ) ::
144+ Date.Range . t ( )
181145 def range ( % { calendar: calendar } = first , % { calendar: calendar } = last , step )
182146 when is_integer ( step ) and step != 0 do
183147 { first_days , _ } = to_iso_days ( first )
@@ -195,24 +159,6 @@ defmodule Date do
195159 "non-zero integer, got: #{ inspect ( first ) } , #{ inspect ( last ) } , #{ step } "
196160 end
197161
198- def range ( % { calendar: _ } = first , % Duration { } = duration , step )
199- when is_integer ( step ) and step != 0 do
200- last = shift ( first , duration )
201- range ( first , last , step )
202- end
203-
204- def range ( % { calendar: _ } = first , duration , step )
205- when is_list ( duration ) and is_integer ( step ) and step != 0 do
206- last = shift ( first , duration )
207- range ( first , last , step )
208- end
209-
210- def range ( % { calendar: _ } = first , last , step ) do
211- raise ArgumentError ,
212- "expected a date or duration as second argument and the step must be a " <>
213- "non-zero integer, got: #{ inspect ( first ) } , #{ inspect ( last ) } , #{ step } "
214- end
215-
216162 defp range ( first , first_days , last , last_days , calendar , step ) do
217163 % Date.Range {
218164 first: % Date { calendar: calendar , year: first . year , month: first . month , day: first . day } ,
@@ -849,7 +795,8 @@ defmodule Date do
849795
850796 """
851797 @ doc since: "1.17.0"
852- @ spec shift ( Calendar . date ( ) , Duration . t ( ) | [ duration_unit_pair ] ) :: t
798+ @ spec shift ( Calendar . date ( ) , Duration . t ( ) | [ unit_pair ] ) :: t
799+ when unit_pair: { :year , integer } | { :month , integer } | { :week , integer } | { :day , integer }
853800 def shift ( % { calendar: calendar } = date , duration ) do
854801 % { year: year , month: month , day: day } = date
855802 { year , month , day } = calendar . shift_date ( year , month , day , __duration__! ( duration ) )
0 commit comments