@@ -127,9 +127,9 @@ lastdayofquarter(dt::DateTime) = DateTime(lastdayofquarter(Date(dt)))
127
127
immutable DateFunction
128
128
f:: Function
129
129
# validate boolean, single-arg inner constructor
130
- function DateFunction (f:: ANY , negate :: Bool , dt:: TimeType )
130
+ function DateFunction (f:: ANY , dt:: TimeType )
131
131
isa (f (dt), Bool) || throw (ArgumentError (" Provided function must take a single TimeType argument and return true or false" ))
132
- return new (negate ? x -> ! f (x) :: Bool : f)
132
+ return new (f)
133
133
end
134
134
end
135
135
Base. show (io:: IO , df:: DateFunction ) = println (io, df. f)
@@ -143,89 +143,130 @@ function adjust(df::DateFunction, start, step, limit)
143
143
throw (ArgumentError (" Adjustment limit reached: $limit iterations" ))
144
144
end
145
145
146
- function adjust (func:: Function , start; step:: Period = Day (1 ), negate:: Bool = false , limit:: Int = 10000 )
147
- return adjust (DateFunction (func, negate, start), start, step, limit)
146
+ function adjust (func:: Function , start; step:: Period = Day (1 ), negate= nothing , limit:: Int = 10000 )
147
+ if negate != = nothing
148
+ deprecate_negate (:adjust , " func,start" , negate)
149
+ negate && (func = ! func)
150
+ end
151
+ return adjust (DateFunction (func, start), start, step, limit)
148
152
end
149
153
150
154
# Constructors using DateFunctions
151
155
152
156
"""
153
- Date(f::Function, y[, m, d]; step=Day(1), negate=false, limit=10000) -> Date
157
+ Date(f::Function, y[, m, d]; step=Day(1), limit=10000) -> Date
154
158
155
159
Create a `Date` through the adjuster API. The starting point will be constructed from the
156
- provided `y, m, d` arguments, and will be adjusted until `f::Function` returns `true`. The
157
- step size in adjusting can be provided manually through the `step` keyword. If
158
- `negate=true`, then the adjusting will stop when `f::Function` returns `false` instead of
159
- `true`. `limit` provides a limit to the max number of iterations the adjustment API will
160
+ provided `y, m, d` arguments, and will be adjusted until `f::Function` returns `true`.
161
+ The step size in adjusting can be provided manually through the `step` keyword.
162
+ `limit` provides a limit to the max number of iterations the adjustment API will
160
163
pursue before throwing an error (given that `f::Function` is never satisfied).
161
164
"""
162
- function Date (func:: Function , y, m= 1 , d= 1 ;step:: Period = Day (1 ), negate:: Bool = false , limit:: Int = 10000 )
163
- return adjust (DateFunction (func, negate, Date (y, m, d)), Date (y, m, d), step, limit)
165
+ function Date (func:: Function , y, m= 1 , d= 1 ;step:: Period = Day (1 ), negate= nothing , limit:: Int = 10000 )
166
+ if negate != = nothing
167
+ deprecate_negate (:Date , " func,y,m,d" , negate)
168
+ negate && (func = ! func)
169
+ end
170
+ return adjust (DateFunction (func, Date (y, m, d)), Date (y, m, d), step, limit)
164
171
end
165
172
166
173
"""
167
- DateTime(f::Function, y[, m, d, h, mi, s]; step=Day(1), negate=false, limit=10000) -> DateTime
174
+ DateTime(f::Function, y[, m, d, h, mi, s]; step=Day(1), limit=10000) -> DateTime
168
175
169
176
Create a `DateTime` through the adjuster API. The starting point will be constructed from
170
177
the provided `y, m, d...` arguments, and will be adjusted until `f::Function` returns
171
- `true`. The step size in adjusting can be provided manually through the `step` keyword. If
172
- `negate=true`, then the adjusting will stop when `f::Function` returns `false` instead of
173
- `true`. `limit` provides a limit to the max number of iterations the adjustment API will
178
+ `true`. The step size in adjusting can be provided manually through the `step` keyword.
179
+ `limit` provides a limit to the max number of iterations the adjustment API will
174
180
pursue before throwing an error (in the case that `f::Function` is never satisfied).
175
181
"""
176
182
DateTime (:: Function , args... )
177
183
178
- function DateTime (func:: Function , y, m= 1 ; step:: Period = Day (1 ), negate:: Bool = false , limit:: Int = 10000 )
179
- return adjust (DateFunction (func, negate, DateTime (y, m)), DateTime (y, m), step, limit)
184
+ function DateTime (func:: Function , y, m= 1 ; step:: Period = Day (1 ), negate= nothing , limit:: Int = 10000 )
185
+ if negate != = nothing
186
+ deprecate_negate (:DateTime , " func,y,m" , negate)
187
+ negate && (func = ! func)
188
+ end
189
+ return adjust (DateFunction (func, DateTime (y, m)), DateTime (y, m), step, limit)
180
190
end
181
- function DateTime (func:: Function , y, m, d; step:: Period = Hour (1 ), negate:: Bool = false , limit:: Int = 10000 )
182
- return adjust (DateFunction (func, negate, DateTime (y)), DateTime (y, m, d), step, limit)
191
+ function DateTime (func:: Function , y, m, d; step:: Period = Hour (1 ), negate= nothing , limit:: Int = 10000 )
192
+ if negate != = nothing
193
+ deprecate_negate (:DateTime , " func,y,m,d" , negate)
194
+ negate && (func = ! func)
195
+ end
196
+ return adjust (DateFunction (func, DateTime (y)), DateTime (y, m, d), step, limit)
183
197
end
184
- function DateTime (func:: Function , y, m, d, h; step:: Period = Minute (1 ), negate:: Bool = false , limit:: Int = 10000 )
185
- return adjust (DateFunction (func, negate, DateTime (y)), DateTime (y, m, d, h), step, limit)
198
+ function DateTime (func:: Function , y, m, d, h; step:: Period = Minute (1 ), negate= nothing , limit:: Int = 10000 )
199
+ if negate != = nothing
200
+ deprecate_negate (:DateTime , " func,y,m,d,h" , negate)
201
+ negate && (func = ! func)
202
+ end
203
+ return adjust (DateFunction (func, DateTime (y)), DateTime (y, m, d, h), step, limit)
186
204
end
187
- function DateTime (func:: Function , y, m, d, h, mi; step:: Period = Second (1 ), negate:: Bool = false , limit:: Int = 10000 )
188
- return adjust (DateFunction (func, negate, DateTime (y)), DateTime (y, m, d, h, mi), step, limit)
205
+ function DateTime (func:: Function , y, m, d, h, mi; step:: Period = Second (1 ), negate= nothing , limit:: Int = 10000 )
206
+ if negate != = nothing
207
+ deprecate_negate (:DateTime , " func,y,m,d,h,mi" , negate)
208
+ negate && (func = ! func)
209
+ end
210
+ return adjust (DateFunction (func, DateTime (y)), DateTime (y, m, d, h, mi), step, limit)
189
211
end
190
- function DateTime (func:: Function , y, m, d, h, mi, s; step:: Period = Millisecond (1 ), negate:: Bool = false , limit:: Int = 10000 )
191
- return adjust (DateFunction (func, negate, DateTime (y)), DateTime (y, m, d, h, mi, s), step, limit)
212
+ function DateTime (func:: Function , y, m, d, h, mi, s; step:: Period = Millisecond (1 ), negate= nothing , limit:: Int = 10000 )
213
+ if negate != = nothing
214
+ deprecate_negate (:DateTime , " func,y,m,d,h,mi,s" , negate)
215
+ negate && (func = ! func)
216
+ end
217
+ return adjust (DateFunction (func, DateTime (y)), DateTime (y, m, d, h, mi, s), step, limit)
192
218
end
193
219
194
220
"""
195
- Time(f::Function, h[, mi, s, ms, us]; step=Second(1), negate=false, limit=10000) -> Time
221
+ Time(f::Function, h[, mi, s, ms, us]; step=Second(1), limit=10000) -> Time
196
222
197
223
Create a `Time` through the adjuster API. The starting point will be constructed from the
198
- provided `h, mi, s, ms, us` arguments, and will be adjusted until `f::Function` returns `true`. The step
199
- size in adjusting can be provided manually through the `step` keyword. If `negate=true`,
200
- then the adjusting will stop when `f::Function` returns `false` instead of `true`. `limit`
224
+ provided `h, mi, s, ms, us` arguments, and will be adjusted until `f::Function` returns `true`.
225
+ The step size in adjusting can be provided manually through the `step` keyword. `limit`
201
226
provides a limit to the max number of iterations the adjustment API will pursue before
202
227
throwing an error (in the case that `f::Function` is never satisfied). Note that the default step
203
228
will adjust to allow for greater precision for the given arguments; i.e. if hour, minute, and second
204
229
arguments are provided, the default step will be `Millisecond(1)` instead of `Second(1)`.
205
230
"""
206
231
Time (:: Function , args... )
207
232
208
- function Time (func:: Function , h, mi= 0 ; step:: Period = Second (1 ), negate:: Bool = false , limit:: Int = 10000 )
209
- return adjust (DateFunction (func, negate, Time (h, mi)), Time (h, mi), step, limit)
233
+ function Time (func:: Function , h, mi= 0 ; step:: Period = Second (1 ), negate= nothing , limit:: Int = 10000 )
234
+ if negate != = nothing
235
+ deprecate_negate (:Time , " func,h,mi" , negate)
236
+ negate && (func = ! func)
237
+ end
238
+ return adjust (DateFunction (func, Time (h, mi)), Time (h, mi), step, limit)
210
239
end
211
- function Time (func:: Function , h, mi, s; step:: Period = Millisecond (1 ), negate:: Bool = false , limit:: Int = 10000 )
212
- return adjust (DateFunction (func, negate, Time (h, mi, s)), Time (h, mi, s), step, limit)
240
+ function Time (func:: Function , h, mi, s; step:: Period = Millisecond (1 ), negate= nothing , limit:: Int = 10000 )
241
+ if negate != = nothing
242
+ deprecate_negate (:Time , " func,h,mi,s" , negate)
243
+ negate && (func = ! func)
244
+ end
245
+ return adjust (DateFunction (func, Time (h, mi, s)), Time (h, mi, s), step, limit)
213
246
end
214
- function Time (func:: Function , h, mi, s, ms; step:: Period = Microsecond (1 ), negate:: Bool = false , limit:: Int = 10000 )
215
- return adjust (DateFunction (func, negate,Time (h, mi, s, ms)),Time (h, mi, s, ms), step, limit)
247
+ function Time (func:: Function , h, mi, s, ms; step:: Period = Microsecond (1 ), negate= nothing , limit:: Int = 10000 )
248
+ if negate != = nothing
249
+ deprecate_negate (:Time , " func,h,mi,s,ms" , negate)
250
+ negate && (func = ! func)
251
+ end
252
+ return adjust (DateFunction (func, Time (h, mi, s, ms)), Time (h, mi, s, ms), step, limit)
216
253
end
217
- function Time (func:: Function , h, mi, s, ms, us; step:: Period = Nanosecond (1 ), negate:: Bool = false , limit:: Int = 10000 )
218
- return adjust (DateFunction (func, negate, Time (h, mi, s, ms, us)), Time (h, mi, s, ms, us), step, limit)
254
+ function Time (func:: Function , h, mi, s, ms, us; step:: Period = Nanosecond (1 ), negate= nothing , limit:: Int = 10000 )
255
+ if negate != = nothing
256
+ deprecate_negate (:Time , " func,h,mi,s,ms,us" , negate)
257
+ negate && (func = ! func)
258
+ end
259
+ return adjust (DateFunction (func, Time (h, mi, s, ms, us)), Time (h, mi, s, ms, us), step, limit)
219
260
end
220
261
221
262
# Return the next TimeType that falls on dow
222
- ISDAYOFWEEK = Dict (Mon => DateFunction (ismonday, false , Date (0 )),
223
- Tue => DateFunction (istuesday, false , Date (0 )),
224
- Wed => DateFunction (iswednesday, false , Date (0 )),
225
- Thu => DateFunction (isthursday, false , Date (0 )),
226
- Fri => DateFunction (isfriday, false , Date (0 )),
227
- Sat => DateFunction (issaturday, false , Date (0 )),
228
- Sun => DateFunction (issunday, false , Date (0 )))
263
+ ISDAYOFWEEK = Dict (Mon => DateFunction (ismonday, Date (0 )),
264
+ Tue => DateFunction (istuesday, Date (0 )),
265
+ Wed => DateFunction (iswednesday, Date (0 )),
266
+ Thu => DateFunction (isthursday, Date (0 )),
267
+ Fri => DateFunction (isfriday, Date (0 )),
268
+ Sat => DateFunction (issaturday, Date (0 )),
269
+ Sun => DateFunction (issunday, Date (0 )))
229
270
230
271
# "same" indicates whether the current date can be considered or not
231
272
"""
@@ -239,15 +280,18 @@ tonext(dt::TimeType, dow::Int; same::Bool=false) = adjust(ISDAYOFWEEK[dow], same
239
280
240
281
# Return the next TimeType where func evals true using step in incrementing
241
282
"""
242
- tonext(func::Function,dt::TimeType;step=Day(1),negate=false, limit=10000,same=false) -> TimeType
283
+ tonext(func::Function,dt::TimeType;step=Day(1),limit=10000,same=false) -> TimeType
243
284
244
285
Adjusts `dt` by iterating at most `limit` iterations by `step` increments until `func`
245
286
returns `true`. `func` must take a single `TimeType` argument and return a `Bool`. `same`
246
- allows `dt` to be considered in satisfying `func`. `negate` will make the adjustment process
247
- terminate when `func` returns `false` instead of `true`.
287
+ allows `dt` to be considered in satisfying `func`.
248
288
"""
249
- function tonext (func:: Function , dt:: TimeType ;step:: Period = Day (1 ), negate:: Bool = false , limit:: Int = 10000 , same:: Bool = false )
250
- return adjust (DateFunction (func, negate, dt), same ? dt : dt+ step, step, limit)
289
+ function tonext (func:: Function , dt:: TimeType ;step:: Period = Day (1 ), negate= nothing , limit:: Int = 10000 , same:: Bool = false )
290
+ if negate != = nothing
291
+ deprecate_negate (:tonext , " func,dt" , negate)
292
+ negate && (func = ! func)
293
+ end
294
+ return adjust (DateFunction (func, dt), same ? dt : dt+ step, step, limit)
251
295
end
252
296
253
297
"""
@@ -260,15 +304,18 @@ Tuesday, etc`. Setting `same=true` allows the current `dt` to be considered as t
260
304
toprev (dt:: TimeType , dow:: Int ; same:: Bool = false ) = adjust (ISDAYOFWEEK[dow], same ? dt : dt+ Day (- 1 ), Day (- 1 ), 7 )
261
305
262
306
"""
263
- toprev(func::Function,dt::TimeType;step=Day(-1),negate=false, limit=10000,same=false) -> TimeType
307
+ toprev(func::Function,dt::TimeType;step=Day(-1),limit=10000,same=false) -> TimeType
264
308
265
309
Adjusts `dt` by iterating at most `limit` iterations by `step` increments until `func`
266
310
returns `true`. `func` must take a single `TimeType` argument and return a `Bool`. `same`
267
- allows `dt` to be considered in satisfying `func`. `negate` will make the adjustment process
268
- terminate when `func` returns `false` instead of `true`.
311
+ allows `dt` to be considered in satisfying `func`.
269
312
"""
270
- function toprev (func:: Function , dt:: TimeType ; step:: Period = Day (- 1 ), negate:: Bool = false , limit:: Int = 10000 , same:: Bool = false )
271
- return adjust (DateFunction (func, negate, dt), same ? dt : dt+ step, step, limit)
313
+ function toprev (func:: Function , dt:: TimeType ; step:: Period = Day (- 1 ), negate= nothing , limit:: Int = 10000 , same:: Bool = false )
314
+ if negate != = nothing
315
+ deprecate_negate (:toprev , " func,dt" , negate)
316
+ negate && (func = ! func)
317
+ end
318
+ return adjust (DateFunction (func, dt), same ? dt : dt+ step, step, limit)
272
319
end
273
320
274
321
# Return the first TimeType that falls on dow in the Month or Year
0 commit comments