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

Ignore time part and timezone #101

Merged
merged 2 commits into from
Mar 8, 2018
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed
- Fixed spelling issue in the Swedish translation. [\#97](https://github.com/azuyalabs/yasumi/pull/97)
- Fixed BetweenFilter to ignore time part and timezone. [\#101](https://github.com/azuyalabs/yasumi/pull/101)

### Removed

Expand Down
10 changes: 5 additions & 5 deletions src/Yasumi/Filters/BetweenFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
class BetweenFilter extends FilterIterator implements Countable
{
/**
* @var \DateTimeInterface start date of the time frame to check against
* @var string start date of the time frame to check against
*/
private $start_date;

/**
* @var \DateTimeInterface end date of the time frame to check against
* @var string end date of the time frame to check against
*/
private $end_date;

Expand All @@ -61,16 +61,16 @@ public function __construct(
) {
parent::__construct($iterator);
$this->equal = $equal;
$this->start_date = $start_date;
$this->end_date = $end_date;
$this->start_date = $start_date->format('Y-m-d');
$this->end_date = $end_date->format('Y-m-d');
}

/**
* @return bool Check whether the current element of the iterator is acceptable
*/
public function accept(): bool
{
$holiday = $this->getInnerIterator()->current();
$holiday = $this->getInnerIterator()->current()->format('Y-m-d');

if ($this->equal && $holiday >= $this->start_date && $holiday <= $this->end_date) {
return true;
Expand Down
23 changes: 23 additions & 0 deletions tests/Base/HolidayBetweenFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ public function testHolidaysBetweenDateRangeWithDateTimeImmutable()
$this->assertNotEquals(\count($holidays), $between->count());
}

/**
* Tests that BetweenFilter considers the date and ignores timezones and time of day.
*/
public function testHolidaysBetweenDateRangeDifferentTimezone()
{
$holidays = Yasumi::create('Netherlands', 2016);

$timezones = ['Pacific/Honolulu', 'Europe/Amsterdam', 'Asia/Tokyo'];

foreach ($timezones as $timezone) {
$between = $holidays->between(
new DateTime('01/01/2016', new DateTimeZone($timezone)),
new DateTime('01/01/2016', new DateTimeZone($timezone))
);
$this->assertCount(1, $between);

$between = $holidays->between(
new DateTime('01/01/2016 23:59:59', new DateTimeZone($timezone)),
new DateTime('01/01/2016 23:59:59', new DateTimeZone($timezone))
);
$this->assertCount(1, $between);
}
}

/**
* Tests the BetweenFilter with date range where start and end date are exclusive of the comparison.
Expand Down