From d7dcfc6c213df77c57549651096272109196033e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:01:24 +0100 Subject: [PATCH] filter public holidays in belgium --- app/Console/Commands/AfterworkCommand.php | 9 +++- composer.json | 1 + composer.lock | 62 ++++++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/AfterworkCommand.php b/app/Console/Commands/AfterworkCommand.php index ad232d9a..d87446fc 100644 --- a/app/Console/Commands/AfterworkCommand.php +++ b/app/Console/Commands/AfterworkCommand.php @@ -6,6 +6,7 @@ use Carbon\CarbonInterval; use Carbon\CarbonPeriod; use Illuminate\Console\Command; +use Spatie\Holidays\Holidays; use Spatie\SlackAlerts\Facades\SlackAlert; class AfterworkCommand extends Command @@ -20,7 +21,9 @@ public function handle(): void ->map(fn (string $option, int $index) => $this->addEmoji($option, $index)) ->implode("\n"); - SlackAlert::message("Who is in for an afterwork drink? :beer: :cup_with_straw:\n{$options}"); + $this->info("Poll options:\n{$options}"); + + SlackAlert::message("Who is in for an afterwork drink? :beer:\n{$options}"); $this->info('Poll posted to Slack'); } @@ -33,6 +36,10 @@ protected function generatePollOptions(): array $datesInMonth = $this->getDatesForWeekdayInMonth($weekday); foreach ($datesInMonth as $date) { + if (Holidays::new()->isHoliday($date, 'be')) { + continue; + } + $options[$date->day] = "{$date->shortDayName} {$date->day}/{$date->month}"; } } diff --git a/composer.json b/composer.json index 6abdd294..3cfc78e0 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,7 @@ "spatie/crypto": "^2.0.1", "spatie/eloquent-sortable": "^4.0.1", "spatie/fork": "^1.1.2", + "spatie/holidays": "^0.0.1", "spatie/laravel-artisan-dispatchable": "^1.3", "spatie/laravel-backup": "^8.1.5", "spatie/laravel-comments": "^1.3", diff --git a/composer.lock b/composer.lock index eaf4b93a..97f75b52 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a56ae13d9974412021e58efcb9a742e3", + "content-hash": "1ecad145dd9aca940aa7f4b8c322a9c7", "packages": [ { "name": "abraham/twitteroauth", @@ -8970,6 +8970,66 @@ ], "time": "2023-11-23T15:12:48+00:00" }, + { + "name": "spatie/holidays", + "version": "0.0.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/holidays.git", + "reference": "5fc21902560f2ab50d995db82b8f836906de2e30" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/holidays/zipball/5fc21902560f2ab50d995db82b8f836906de2e30", + "reference": "5fc21902560f2ab50d995db82b8f836906de2e30", + "shasum": "" + }, + "require": { + "ext-calendar": "*", + "nesbot/carbon": "^2.72", + "php": "^8.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.21.1", + "pestphp/pest": "^2.15", + "phpstan/phpstan": "^1.10", + "spatie/ray": "^1.28" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Holidays\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Niels Vanpachtenbeke", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Calculate public holidays", + "homepage": "https://github.com/spatie/holidays", + "keywords": [ + "holidays", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/holidays/issues", + "source": "https://github.com/spatie/holidays/tree/0.0.1" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-01-15T10:55:39+00:00" + }, { "name": "spatie/ignition", "version": "1.11.3",