Skip to content

Commit

Permalink
Merge pull request #170 from thecaliskan/main
Browse files Browse the repository at this point in the history
Added has helper
  • Loading branch information
Nielsvanpach authored Jan 23, 2024
2 parents f9423cf + e932a2d commit 948c63a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ use Spatie\Holidays\Holidays;
Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar
```

### Determining whether a country is supported

To verify whether a country is supported, you can use the `has` method.

```php
use Spatie\Holidays\Holidays;

Holidays::has('be'); // true
Holidays::has('unknown'); // false
```

### Package limitations
1. Islamic holidays are not supported (yet)

Expand Down
5 changes: 5 additions & 0 deletions src/Holidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public static function for(Country|string $country, ?int $year = null): static
return new static($country, $year);
}

public static function has(string $country): bool
{
return Country::find($country) instanceof Country;
}

/** @return array<array{name: string, date: string}> */
public function get(Country|string|null $country = null, ?int $year = null): array
{
Expand Down
8 changes: 8 additions & 0 deletions tests/HolidaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@
$result = Holidays::for('be')->getName(CarbonImmutable::parse('2024-01-02'));
expect($result)->toBeNull();
});

it('can get the country is supported', function () {
$result = Holidays::has(country: 'be');
expect($result)->toBeTrue();

$result = Holidays::has(country: 'unknown');
expect($result)->toBeFalse();
});

0 comments on commit 948c63a

Please sign in to comment.