@@ -69,11 +69,6 @@ defmodule Date do
69
69
calendar: Calendar . calendar ( )
70
70
}
71
71
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
-
77
72
@ doc """
78
73
Returns a range of dates.
79
74
@@ -89,20 +84,6 @@ defmodule Date do
89
84
iex> Date.range(~D[1999-01-01], ~D[2000-01-01])
90
85
Date.range(~D[1999-01-01], ~D[2000-01-01])
91
86
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
-
106
87
A range of dates implements the `Enumerable` protocol, which means
107
88
functions in the `Enum` module can be used to work with
108
89
ranges:
@@ -119,11 +100,7 @@ defmodule Date do
119
100
120
101
"""
121
102
@ 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 ( )
127
104
def range ( % { calendar: calendar } = first , % { calendar: calendar } = last ) do
128
105
{ first_days , _ } = to_iso_days ( first )
129
106
{ last_days , _ } = to_iso_days ( last )
@@ -146,16 +123,6 @@ defmodule Date do
146
123
raise ArgumentError , "both dates must have matching calendars"
147
124
end
148
125
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
-
159
126
@ doc """
160
127
Returns a range of dates with a step.
161
128
@@ -173,11 +140,8 @@ defmodule Date do
173
140
174
141
"""
175
142
@ 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 ( )
181
145
def range ( % { calendar: calendar } = first , % { calendar: calendar } = last , step )
182
146
when is_integer ( step ) and step != 0 do
183
147
{ first_days , _ } = to_iso_days ( first )
@@ -195,24 +159,6 @@ defmodule Date do
195
159
"non-zero integer, got: #{ inspect ( first ) } , #{ inspect ( last ) } , #{ step } "
196
160
end
197
161
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
-
216
162
defp range ( first , first_days , last , last_days , calendar , step ) do
217
163
% Date.Range {
218
164
first: % Date { calendar: calendar , year: first . year , month: first . month , day: first . day } ,
@@ -849,7 +795,8 @@ defmodule Date do
849
795
850
796
"""
851
797
@ 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 }
853
800
def shift ( % { calendar: calendar } = date , duration ) do
854
801
% { year: year , month: month , day: day } = date
855
802
{ year , month , day } = calendar . shift_date ( year , month , day , __duration__! ( duration ) )
0 commit comments