Skip to content

Instantly share code, notes, and snippets.

@samoldenburg
Created January 25, 2019 16:53
Show Gist options
  • Save samoldenburg/a4f1849047c34b5f42f2cdc9deedd304 to your computer and use it in GitHub Desktop.
Save samoldenburg/a4f1849047c34b5f42f2cdc9deedd304 to your computer and use it in GitHub Desktop.
Output list of dates to a text file between start and end excluding weekends
<?php
namespace App\Console\Commands;
use App\Extensions\Command;
use Illuminate\Support\Carbon;
class TestCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Test';
/**
* How long would you like to keep this history for?
* Note that if the history is less than 21 days
* eyewitness may have incomplete graphs.
*
* @var int
*/
public $keepHistoryFor = 21;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$start = new Carbon("2019-05-03");
$end = new Carbon("2019-09-30");
$dates = [];
while ($start <= $end) {
if ($start->isWeekend()) {
$start->addDay(1);
continue;
}
$dates[] = $start->format('n/j/y');
$start->addDay(1);
}
file_put_contents(__DIR__ . '/dates.txt', collect($dates)->implode("\r\n"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment