Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle invalid timezones Australia/ACT and Europe/Kiev #343

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 11 additions & 24 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the Yasumi package.
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
Expand All @@ -12,29 +14,14 @@
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/
$finder = PhpCsFixer\Finder::create()->in(__DIR__);

$config = new PhpCsFixer\Config();
$config->setRiskyAllowed(true)->setRules([
'@PER' => true,
'@Symfony' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'explicit_string_variable' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true],
'not_operator_with_successor_space' => true,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true ],
'ordered_class_elements' => true,
$config = new AzuyaLabs\PhpCsFixerConfig\Config('2015', null, 'Yasumi');
$config->getFinder()->in(__DIR__)->notPath('var');

$defaults = $config->getRules();

// Risky
'declare_strict_types' => true,
'dir_constant' => true,
'get_class_to_class_keyword' => true,
'is_null' => true,
'modernize_strpos' => true,
'modernize_types_casting' => true,
'self_accessor' => true,
])->setFinder($finder);
$config->setRules(array_merge($defaults, [
'php_unit_method_casing' => ['case' => 'camel_case'],
]));

return $config;
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ changes.

### Changed

- Holiday calculation methods in providers are now protected instead of private
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, that must have been my IDE 🤷

to allow use in [custom providers](https://www.yasumi.dev/docs/cookbook/custom_provider/).
[\#331](https://github.com/azuyalabs/yasumi/issues/331)

### Fixed

- Handle invalid/changed timezones Australia/ACT and Europe/Kiev [\#343](https://github.com/azuyalabs/yasumi/pull/343)
([Kevin Papst](https://github.com/kevinpapst))

### Removed

## [2.7.0] - 2024-01-02
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azuyalabs/yasumi",
"description": "The easy PHP Library for calculating holidays.",
"description": "The easy PHP Library for calculating holidays",
"license": "MIT",
"type": "library",
"keywords": [
Expand Down Expand Up @@ -40,12 +40,12 @@
},
"require-dev": {
"ext-intl": "*",
"friendsofphp/php-cs-fixer": "^2.19 || ^3.40",
"azuyalabs/php-cs-fixer-config": "^0.3",
"mikey179/vfsstream": "^1.6",
"phan/phan": "^5.4",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^8.5 || ^9.6",
"vimeo/psalm": "^5.16"
"vimeo/psalm": "^5.20"
},
"suggest": {
"ext-calendar": "For calculating the date of Easter"
Expand All @@ -72,7 +72,8 @@
"@phpstan",
"@psalm"
],
"format": "./vendor/bin/php-cs-fixer fix",
"cs": "vendor/bin/php-cs-fixer fix -v --diff --dry-run",
"cs-fix": "vendor/bin/php-cs-fixer fix -v",
"phan": "vendor/bin/phan -C",
"phpstan": "vendor/bin/phpstan analyse",
"psalm": "vendor/bin/psalm --threads=2",
Expand Down
33 changes: 23 additions & 10 deletions examples/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,59 @@

// This file demonstrates the general use of Yasumi and its basic methods.

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

require 'vendor/autoload.php';

// Use the factory to create a new holiday provider instance
$holidays = Yasumi\Yasumi::create('USA', (int) date('Y'));

// Show the number of defined holidays
echo 'Number of defined holidays: '.$holidays->count().PHP_EOL;
echo 'Number of defined holidays: ' . $holidays->count() . PHP_EOL;
echo PHP_EOL;

// Display a list all of the holiday names (short names)
echo 'List of all the holiday names: '.PHP_EOL;
echo 'List of all the holiday names: ' . PHP_EOL;
foreach ($holidays->getHolidayNames() as $name) {
echo $name.PHP_EOL;
echo $name . PHP_EOL;
}
echo PHP_EOL;

// Display a list all of the holiday dates
echo 'List of all the holiday dates:'.PHP_EOL;
echo 'List of all the holiday dates:' . PHP_EOL;
foreach ($holidays->getHolidayDates() as $date) {
echo $date.PHP_EOL;
echo $date . PHP_EOL;
}
echo PHP_EOL;

// Get a holiday instance for Independence Day
$independenceDay = $holidays->getHoliday('independenceDay');

// Show the localized name
echo 'Name of the holiday : '.$independenceDay->getName().PHP_EOL;
echo 'Name of the holiday : ' . $independenceDay->getName() . PHP_EOL;

// Show the date
echo 'Date of the holiday : '.$independenceDay.PHP_EOL;
echo 'Date of the holiday : ' . $independenceDay . PHP_EOL;

// Show the type of holiday
echo 'Type of holiday : '.$independenceDay->getType().PHP_EOL;
echo 'Type of holiday : ' . $independenceDay->getType() . PHP_EOL;
echo PHP_EOL;

// Dump the holiday as a JSON object
echo 'Holiday as a JSON object:'.PHP_EOL;
echo 'Holiday as a JSON object:' . PHP_EOL;
echo json_encode($independenceDay, JSON_PRETTY_PRINT);

echo PHP_EOL;
25 changes: 19 additions & 6 deletions examples/between_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
// This file demonstrates the use of the `between` filter, selecting only a number of holidays
// that fall in the given date range.

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

require 'vendor/autoload.php';

Expand All @@ -12,16 +25,16 @@
// Use the factory to create a new holiday provider instance
$holidays = Yasumi\Yasumi::create('Italy', $year);
$holidaysInDecember = $holidays->between(
new DateTime('12/01/'.$year),
new DateTime('12/31/'.$year)
new DateTime('12/01/' . $year),
new DateTime('12/31/' . $year)
);

// Show all holidays in Italy for December
echo 'List of all the holidays in December: '.PHP_EOL;
echo 'List of all the holidays in December: ' . PHP_EOL;
foreach ($holidaysInDecember as $holiday) {
echo $holiday.' - '.$holiday->getName().PHP_EOL;
echo $holiday . ' - ' . $holiday->getName() . PHP_EOL;
}
echo PHP_EOL;

// Show the number of filtered holidays
echo 'Number of filtered holidays: '.$holidaysInDecember->count().PHP_EOL;
echo 'Number of filtered holidays: ' . $holidaysInDecember->count() . PHP_EOL;
21 changes: 17 additions & 4 deletions examples/custom_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
// those scenarios where you would need only a subset of holidays of an existing provider. Or, if you you like to
// extend an existing provider with additional, non-standard holidays.

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

require 'vendor/autoload.php';

Expand Down Expand Up @@ -33,11 +46,11 @@ public function initialize(): void
$NYSEHolidays = Yasumi\Yasumi::create(NYSE::class, (int) date('Y'));

// We then can retrieve the NYSE observed holidays in the usual manner:
echo 'List of all the holiday names: '.PHP_EOL;
echo 'List of all the holiday names: ' . PHP_EOL;
foreach ($NYSEHolidays->getHolidayNames() as $day) {
echo $day.PHP_EOL;
echo $day . PHP_EOL;
}
echo PHP_EOL;

// Use the count() method to show how many holidays are returned
echo 'Number of defined holidays: '.$NYSEHolidays->count().PHP_EOL;
echo 'Number of defined holidays: ' . $NYSEHolidays->count() . PHP_EOL;
19 changes: 16 additions & 3 deletions examples/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
// based on certain conditions. In this examples we show only the holidays that are
// marked as 'official'.

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

require 'vendor/autoload.php';

Expand All @@ -14,7 +27,7 @@
// Create a filter instance for the official holidays
$official = new Yasumi\Filters\OfficialHolidaysFilter($holidays->getIterator());

echo 'List of all official holidays: '.PHP_EOL;
echo 'List of all official holidays: ' . PHP_EOL;
foreach ($official as $day) {
echo $day->getName().PHP_EOL;
echo $day->getName() . PHP_EOL;
}
15 changes: 14 additions & 1 deletion phpinsights.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

return [
/*
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
verbose="true"
>

<php>
<ini name="memory_limit" value="512M" />
</php>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/Yasumi</directory>
Expand Down
19 changes: 16 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/src',
__DIR__.'/tests',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// single rules
Expand Down
8 changes: 5 additions & 3 deletions src/Yasumi/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

/*
* This file is part of the Yasumi package.
/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
Expand Down
8 changes: 5 additions & 3 deletions src/Yasumi/Exception/InvalidYearException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

/*
* This file is part of the Yasumi package.
/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
Expand Down
8 changes: 5 additions & 3 deletions src/Yasumi/Exception/MissingTranslationException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

/*
* This file is part of the Yasumi package.
/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
Expand Down
Loading
Loading