From 3b86b79cdb39c2f85a1044a4abbc594ea526525d Mon Sep 17 00:00:00 2001 From: Jacob Bennett Date: Fri, 2 Sep 2016 10:39:15 -0500 Subject: [PATCH] Include documentation for between and unlessBetween Add examples and some additional details for [this feature](https://github.com/laravel/framework/pull/15216) --- scheduling.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scheduling.md b/scheduling.md index 0d74fa924b..076dc6675e 100644 --- a/scheduling.md +++ b/scheduling.md @@ -103,9 +103,7 @@ These methods may be combined with additional constraints to create even more fi ->weekdays() ->hourly() ->timezone('America/Chicago') - ->when(function () { - return date('H') >= 8 && date('H') <= 17; - }); + ->between('8:00', '17:00'); Below is a list of the additional schedule constraints: @@ -120,6 +118,7 @@ Method | Description `->fridays();` | Limit the task to Friday `->saturdays();` | Limit the task to Saturday `->when(Closure);` | Limit the task based on a truth test +`->between($start, $end);` | Limit the task to run between start and end times #### Truth Test Constraints @@ -138,6 +137,17 @@ The `skip` method may be seen as the inverse of `when`. If the `skip` method ret When using chained `when` methods, the scheduled command will only execute if all `when` conditions return `true`. + +#### Between Time Constraints + +The `between` method may be used to limit the execution of a task based on the time of day. + + $schedule->command('reminders:send')->hourly()->between('7:00', '22:00'); + +Similarly, the `unlessBetween` method can be used to exclude the execution of a task for a period of time. + + $schedule->command('reminders:send')->hourly()->unlessBetween('23:00', '4:00'); + ### Preventing Task Overlaps By default, scheduled tasks will be run even if the previous instance of the task is still running. To prevent this, you may use the `withoutOverlapping` method: