Skip to content

Commit

Permalink
Added filters feature. Using Yasumi you can filter holiday providers …
Browse files Browse the repository at this point in the history
…to only show official holidays, observed holidays, bank holidays, seasonal holidays or other type of holidays.
  • Loading branch information
stelgenhof committed Apr 21, 2015
1 parent d48ffc8 commit 74e89c0
Show file tree
Hide file tree
Showing 7 changed files with 410 additions and 9 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Highlights
* Common Holiday Providers
* Global Translations
* Implements ArrayIterator to easily process a provider's holidays
* Filters enabling to easily select certain holiday types (Official, Observed, Bank, Seasonal or Other)
* Fully documented
* Fully Unit tested
* Framework-agnostic
Expand All @@ -35,6 +36,14 @@ Currently the following holiday providers are implemented:
* Italy
* France

Yasumi has the following filters to allow you to filter only certain type of holidays:

* Official
* Observed
* Bank
* Seasonal
* Other


System Requirements
-------------------
Expand Down Expand Up @@ -82,17 +91,18 @@ Basic Usage
require 'vendor/autoload.php';

use Yasumi\Yasumi;
use Yasumi\Filters\OfficialHolidaysFilter;

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

// Get the number of defined holidays
echo $holidays->count() . PHP_EOL;
echo $holidays->count();
// 11

// Get a list all of the holiday names (short names)
foreach ($holidays->getHolidayNames() as $name) {
echo $name . PHP_EOL;
echo $name;
}
// 'newYearsDay'
// 'martinLutherKingDay'
Expand All @@ -108,7 +118,7 @@ foreach ($holidays->getHolidayNames() as $name) {

// Get a list all of the holiday dates
foreach ($holidays->getHolidayDates() as $date) {
echo $date . PHP_EOL;
echo $date;
}
// '2015-01-01'
// '2015-01-19'
Expand All @@ -126,28 +136,44 @@ foreach ($holidays->getHolidayDates() as $date) {
$independenceDay = $holidays->getHoliday('independenceDay');

// Get the localized name
echo $independenceDay->getName() . PHP_EOL;
echo $independenceDay->getName();
// 'Independence Day'

// Get the date
echo $independenceDay . PHP_EOL;
echo $independenceDay;
// '2015-07-04'

// Get the type of holiday
echo $independenceDay->getType() . PHP_EOL;
echo $independenceDay->getType();
// 'national'

// Print the holiday as a JSON object
echo json_encode($independenceDay, JSON_PRETTY_PRINT);
//{
// {
// "shortName": "independenceDay",
// "translations": {
// "en_US": "Independence Day"
// },
// "date": "2015-07-04 00:00:00.000000",
// "timezone_type": 3,
// "timezone": "America\/New_York"
//}
// }

// Retrieve only the official holidays for the Netherlands in 2014
$holidays = Yasumi::create('Netherlands', 2014);
$official = new OfficialHolidaysFilter($holidays->getIterator());
foreach ($official as $day) {
echo $day->getName();
}
// 'New Year's Day'
// 'Easter Sunday'
// 'Easter Monday'
// 'Kings Day'
// 'Ascension Day'
// 'Whitsunday'
// 'Whitmonday'
// 'Christmas'
// 'Boxing Day'
```


Expand All @@ -157,7 +183,7 @@ Roadmap
Yasumi is still in development and a stable release is coming soon. For its first release, we will have the following
included:

- Filters
- ~~Filters~~
- ~~Global Translations~~
- ~~Common holiday providers~~
- Additional countries (~~Italy~~ and ~~France~~)
Expand Down
40 changes: 40 additions & 0 deletions src/Yasumi/Filters/BankHolidaysFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/
namespace Yasumi\Filters;

use FilterIterator;
use Yasumi\Holiday;

/**
* BankHolidaysFilter is a class for filtering all bank holidays
*
* BankHolidaysFilter is a class that returns all holidays that are considered bank holidays of any given holiday
* provider.
*
* Example usage:
* $holidays = Yasumi::create('Netherlands', 2015);
* $bank = new BankHolidaysFilter($holidays->getIterator());
*
* @package Yasumi
*/
class BankHolidaysFilter extends FilterIterator
{
/**
* Checks whether the current element of the iterator is an observed holiday
*
* @return bool
*/
public function accept()
{
return ($this->getInnerIterator()->current()->getType() === Holiday::TYPE_BANK) ? true : false;
}
}
40 changes: 40 additions & 0 deletions src/Yasumi/Filters/ObservedHolidaysFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/
namespace Yasumi\Filters;

use FilterIterator;
use Yasumi\Holiday;

/**
* ObservedHolidaysFilter is a class for filtering all observed holidays
*
* ObservedHolidaysFilter is a class that returns all holidays that are considered observed of any given holiday
* provider.
*
* Example usage:
* $holidays = Yasumi::create('Netherlands', 2015);
* $observed = new ObservedHolidaysFilter($holidays->getIterator());
*
* @package Yasumi
*/
class ObservedHolidaysFilter extends FilterIterator
{
/**
* Checks whether the current element of the iterator is an observed holiday
*
* @return bool
*/
public function accept()
{
return ($this->getInnerIterator()->current()->getType() === Holiday::TYPE_OBSERVANCE) ? true : false;
}
}
40 changes: 40 additions & 0 deletions src/Yasumi/Filters/OfficialHolidaysFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/
namespace Yasumi\Filters;

use FilterIterator;
use Yasumi\Holiday;

/**
* OfficialHolidaysFilter is a class for filtering all official holidays
*
* OfficialHolidaysFilter is a class that returns all holidays that are considered official (i.e. national) of any given
* holiday provider.
*
* Example usage:
* $holidays = Yasumi::create('Netherlands', 2015);
* $official = new OfficialHolidaysFilter($holidays->getIterator());
*
* @package Yasumi
*/
class OfficialHolidaysFilter extends FilterIterator
{
/**
* Checks whether the current element of the iterator is a national/official holiday
*
* @return bool
*/
public function accept()
{
return ($this->getInnerIterator()->current()->getType() === Holiday::TYPE_NATIONAL) ? true : false;
}
}
40 changes: 40 additions & 0 deletions src/Yasumi/Filters/OtherHolidaysFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/
namespace Yasumi\Filters;

use FilterIterator;
use Yasumi\Holiday;

/**
* OtherHolidaysFilter is a class for filtering all other type of holidays
*
* OtherHolidaysFilter is a class that returns all holidays that are considered an other type of holiday of any given
* holiday provider.
*
* Example usage:
* $holidays = Yasumi::create('Netherlands', 2015);
* $other = new OtherHolidaysFilter($holidays->getIterator());
*
* @package Yasumi
*/
class OtherHolidaysFilter extends FilterIterator
{
/**
* Checks whether the current element of the iterator is an other type of holiday
*
* @return bool
*/
public function accept()
{
return ($this->getInnerIterator()->current()->getType() === Holiday::TYPE_OTHER) ? true : false;
}
}
40 changes: 40 additions & 0 deletions src/Yasumi/Filters/SeasonalHolidaysFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/
namespace Yasumi\Filters;

use FilterIterator;
use Yasumi\Holiday;

/**
* SeasonalHolidaysFilter is a class for filtering all seasonal holidays
*
* OfficialHolidaysFilter is a class that returns all holidays that are considered seasonal of any given holiday
* provider.
*
* Example usage:
* $holidays = Yasumi::create('Netherlands', 2015);
* $seasonal = new SeasonalHolidaysFilter($holidays->getIterator());
*
* @package Yasumi
*/
class SeasonalHolidaysFilter extends FilterIterator
{
/**
* Checks whether the current element of the iterator is a seasonal holiday
*
* @return bool
*/
public function accept()
{
return ($this->getInnerIterator()->current()->getType() === Holiday::TYPE_SEASON) ? true : false;
}
}
Loading

0 comments on commit 74e89c0

Please sign in to comment.