|
2 | 2 |
|
3 | 3 | namespace Studio\Totem\Console\Commands;
|
4 | 4 |
|
| 5 | +use Carbon\Carbon; |
| 6 | +use Cron\CronExpression; |
5 | 7 | use Illuminate\Console\Command;
|
6 | 8 | use Illuminate\Console\Scheduling\Schedule;
|
7 | 9 |
|
@@ -49,17 +51,36 @@ public function handle()
|
49 | 51 | if (count($this->schedule->events()) > 0) {
|
50 | 52 | $events = collect($this->schedule->events())->map(function ($event) {
|
51 | 53 | return [
|
52 |
| - 'command' => ltrim(str_after($event->command, "'artisan'")), |
53 |
| - 'schedule' => $event->expression, |
| 54 | + 'command' => ltrim(str_after($event->command, "'artisan'")), |
| 55 | + 'schedule' => $event->expression, |
| 56 | + 'upcoming' => $this->upcoming($event), |
| 57 | + 'description' => $event->description, |
| 58 | + 'timezone' => $event->timezone |
54 | 59 | ];
|
55 | 60 | });
|
56 | 61 |
|
57 | 62 | $this->table(
|
58 |
| - ['Command', 'Schedule'], |
| 63 | + ['Command', 'Schedule', 'Upcoming', 'Description', 'Timezone'], |
59 | 64 | $events
|
60 | 65 | );
|
61 | 66 | } else {
|
62 | 67 | $this->info('No Scheduled Commands Found');
|
63 | 68 | }
|
64 | 69 | }
|
| 70 | + |
| 71 | + /** |
| 72 | + * Get Upcoming schedule. |
| 73 | + * |
| 74 | + * @return bool |
| 75 | + */ |
| 76 | + protected function upcoming($event) |
| 77 | + { |
| 78 | + $date = Carbon::now(); |
| 79 | + |
| 80 | + if ($event->timezone) { |
| 81 | + $date->setTimezone($event->timezone); |
| 82 | + } |
| 83 | + |
| 84 | + return (CronExpression::factory($event->expression)->getNextRunDate($date->toDateTimeString()))->format('Y-m-d H:i:s'); |
| 85 | + } |
65 | 86 | }
|
0 commit comments