Skip to content

Commit

Permalink
Fix #18: I18n Support
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKoerner committed Jul 5, 2017
1 parent fba86aa commit 5c136b8
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 194 deletions.
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
README [![Build Status](https://travis-ci.org/checkdomain/Holiday.png?branch=master)](https://travis-ci.org/checkdomain/Holiday)
======
# checkdomain Holiday [![Build Status](https://travis-ci.org/checkdomain/Holiday.png?branch=master)](https://travis-ci.org/checkdomain/Holiday)

What is Checkdomain/Holiday
---------------------------
Checkdomain/Holiday is a small library to check if a specified date is a holiday in a specific country. It also tells you if the given date is a nation wide holiday or just a holiday in some states.

Requirements
------------

## Currently supported countries

- **AT** Austria
- **DE** Germany
- **DK** Denmark
- **FR** France
- **IT** Italy
- **NO** Norway
- **PL** Poland
- **PT** Portugal
- **SE** Sweden

## Your country is not supported?

checkdomain Holiday is open source. If you use this library it would be great to get some support for currently not implemented countries which you are familiar with. Pull requests will be reviewed and merged fast.

To create a new Provider please see the `ProviderInterface` interface.


## Requirements

Checkdomain/Holiday requires php >= 5.3.

Installation
------------

## Installation

The easiest way to install this library is through [composer](http://getcomposer.org/). Just add the following lines to your **composer.json** file:

```json
Expand All @@ -23,25 +41,21 @@ The easiest way to install this library is through [composer](http://getcomposer

Another way would be to download this library and configure the autoloading yourself. This library relies on a [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) compatible autoloader for automatic class loading.

Usage
-----

## Usage

To check for holidays just instantiate the Util class and call the `getHoliday` method.

```php
$util = new \Checkdomain\Holiday\Util();
$holiday = $util->getHoliday('DE', '01.01.2014');
$holiday = $util->getHoliday('DE', '2014-01-01');
```

If you just need to know if there is a holiday on your date there is a `isHoliday` method, too.

If you need to know all holidays for a specific country you can instantiate one of the included providers yourself and call the `getHolidaysByYear` method. All providers must follow the `ProviderInterface` interface.

Contributing
------------
Checkdomain/Holiday is open source. If you use this library it would be great to get some support for currently not implemented countries which you are familiar with. Pull requests will be reviewed and merged fast.

To create a new Provider please see the `ProviderInterface` interface.
## Running Tests

Running Tests
-------------
Run a `php composer.phar install` command in the base directory to install the `phpunit` dependency. After that you can simply call `vendor/bin/phpunit tests/` to run the test suite.
52 changes: 26 additions & 26 deletions tests/Checkdomain/Holiday/Provider/ATTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ public function setUp()
public function dateProvider()
{
return array(
array('01.01.2013', null, array('name' => 'Neujahr')),
array('06.01.2013', null, array('name' => 'Heilige Drei Könige')),
array('01.04.2013', null, array('name' => 'Ostermontag')),
array('01.05.2013', null, array('name' => 'Staatsfeiertag')),
array('09.05.2013', null, array('name' => 'Christi Himmelfahrt')),
array('20.05.2013', null, array('name' => 'Pfingstmontag')),
array('30.05.2013', null, array('name' => 'Fronleichnam')),
array('15.08.2013', null, array('name' => 'Mariä Himmelfahrt')),
array('26.10.2013', null, array('name' => 'Nationalfeiertag')),
array('01.11.2013', null, array('name' => 'Allerheiligen')),
array('08.12.2013', null, array('name' => 'Mariä Empfängnis')),
array('25.12.2013', null, array('name' => 'Weihnachten')),
array('26.12.2013', null, array('name' => 'Stefanitag')),
array('01.01.2015', null, array('name' => 'Neujahr')),
array('06.01.2015', null, array('name' => 'Heilige Drei Könige')),
array('06.04.2015', null, array('name' => 'Ostermontag')),
array('01.05.2015', null, array('name' => 'Staatsfeiertag')),
array('14.05.2015', null, array('name' => 'Christi Himmelfahrt')),
array('25.05.2015', null, array('name' => 'Pfingstmontag')),
array('04.06.2015', null, array('name' => 'Fronleichnam')),
array('15.08.2015', null, array('name' => 'Mariä Himmelfahrt')),
array('26.10.2015', null, array('name' => 'Nationalfeiertag')),
array('01.11.2015', null, array('name' => 'Allerheiligen')),
array('08.12.2015', null, array('name' => 'Mariä Empfängnis')),
array('25.12.2015', null, array('name' => 'Weihnachten')),
array('26.12.2015', null, array('name' => 'Stefanitag')),
array('2013-01-01', null, array('name' => 'Neujahr')),
array('2013-01-06', null, array('name' => 'Heilige Drei Könige')),
array('2013-04-01', null, array('name' => 'Ostermontag')),
array('2013-05-01', null, array('name' => 'Staatsfeiertag')),
array('2013-05-09', null, array('name' => 'Christi Himmelfahrt')),
array('2013-05-20', null, array('name' => 'Pfingstmontag')),
array('2013-05-30', null, array('name' => 'Fronleichnam')),
array('2013-08-15', null, array('name' => 'Mariä Himmelfahrt')),
array('2013-10-26', null, array('name' => 'Nationalfeiertag')),
array('2013-11-01', null, array('name' => 'Allerheiligen')),
array('2013-12-08', null, array('name' => 'Mariä Empfängnis')),
array('2013-12-25', null, array('name' => 'Weihnachten')),
array('2013-12-26', null, array('name' => 'Stefanitag')),
array('2015-01-01', null, array('name' => 'Neujahr')),
array('2015-01-06', null, array('name' => 'Heilige Drei Könige')),
array('2015-04-06', null, array('name' => 'Ostermontag')),
array('2015-05-01', null, array('name' => 'Staatsfeiertag')),
array('2015-05-14', null, array('name' => 'Christi Himmelfahrt')),
array('2015-05-25', null, array('name' => 'Pfingstmontag')),
array('2015-06-04', null, array('name' => 'Fronleichnam')),
array('2015-08-15', null, array('name' => 'Mariä Himmelfahrt')),
array('2015-10-26', null, array('name' => 'Nationalfeiertag')),
array('2015-11-01', null, array('name' => 'Allerheiligen')),
array('2015-12-08', null, array('name' => 'Mariä Empfängnis')),
array('2015-12-25', null, array('name' => 'Weihnachten')),
array('2015-12-26', null, array('name' => 'Stefanitag')),
);
}
}
2 changes: 1 addition & 1 deletion tests/Checkdomain/Holiday/Provider/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testHolidays($date, $state = null, array $expectation = null)
$this->assertNull($holiday);
} else {
$this->assertNotNull($holiday, 'No Holiday found but assumed to find one on ' . $date->format('Y-m-d'));
$this->assertEquals($date->format('d.m.Y'), $holiday->getDate()->format('d.m.Y'));
$this->assertEquals($date->format('Y-m-d'), $holiday->getDate()->format('Y-m-d'));

foreach ($expectation as $property => $expectedValue) {
$method = 'get' . ucfirst($property);
Expand Down
16 changes: 8 additions & 8 deletions tests/Checkdomain/Holiday/Provider/DETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function setUp()
public function dateProvider()
{
return array(
array('21.03.2013', null, null),
array('01.01.2013', null, array('name' => 'Neujahr')),
array('06.01.2013', DE::STATE_BY, array('name' => 'Heilige Drei Könige')),
array('06.01.2013', DE::STATE_SH, null),
array('19.06.2014', DE::STATE_HE, array('name' => 'Fronleichnam')),
array('19.06.2014', DE::STATE_SH, null),
array('01.11.2014', DE::STATE_BW, array('name' => 'Allerheiligen')),
array('01.11.2014', DE::STATE_SH, null),
array('2013-03-21', null, null),
array('2013-01-01', null, array('name' => 'Neujahr')),
array('2013-01-06', DE::STATE_BY, array('name' => 'Heilige Drei Könige')),
array('2013-01-06', DE::STATE_SH, null),
array('2014-06-19', DE::STATE_HE, array('name' => 'Fronleichnam')),
array('2014-06-19', DE::STATE_SH, null),
array('2014-11-01', DE::STATE_BW, array('name' => 'Allerheiligen')),
array('2014-11-01', DE::STATE_SH, null),
);
}
}
22 changes: 11 additions & 11 deletions tests/Checkdomain/Holiday/Provider/DKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public function setUp()
public function dateProvider()
{
return array(
array('01.01.2016', null, array('name' => 'Nytår')),
array('24.03.2016', null, array('name' => 'Skærtorsdag')),
array('25.03.2016', null, array('name' => 'Langfredag')),
array('27.03.2016', null, array('name' => 'Påskedag')),
array('28.03.2016', null, array('name' => '2. Påskedag')),
array('22.04.2016', null, array('name' => 'Store Bededag')),
array('05.05.2016', null, array('name' => 'Kristi Himmelfartsdag')),
array('15.05.2016', null, array('name' => 'Pinsedag')),
array('16.05.2016', null, array('name' => '2. Pinsedag')),
array('25.12.2016', null, array('name' => '1. Juledag')),
array('26.12.2016', null, array('name' => '2. Juledag')),
array('2016-01-01', null, array('name' => 'Nytår')),
array('2016-03-24', null, array('name' => 'Skærtorsdag')),
array('2016-03-25', null, array('name' => 'Langfredag')),
array('2016-03-27', null, array('name' => 'Påskedag')),
array('2016-03-28', null, array('name' => '2. Påskedag')),
array('2016-04-22', null, array('name' => 'Store Bededag')),
array('2016-05-05', null, array('name' => 'Kristi Himmelfartsdag')),
array('2016-05-15', null, array('name' => 'Pinsedag')),
array('2016-05-16', null, array('name' => '2. Pinsedag')),
array('2016-12-25', null, array('name' => '1. Juledag')),
array('2016-12-26', null, array('name' => '2. Juledag')),
);
}
}
24 changes: 12 additions & 12 deletions tests/Checkdomain/Holiday/Provider/FRTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ public function testHolidays($date, $state = null, array $expectation = null)
public function dateProvider()
{
return array(
array('21.03.2014', null, null),
array('01.01.2014', null, array('name' => 'Jour de l\'an')),
array('21.04.2014', null, array('name' => 'Lundi de Pâques')),
array('01.05.2014', null, array('name' => 'Fête du Travail')),
array('08.05.2014', null, array('name' => '8 Mai 1945')),
array('29.05.2014', null, array('name' => 'Jeudi de l\'Ascension')),
array('09.06.2014', null, array('name' => 'Lundi de Pentecôte')),
array('14.07.2014', null, array('name' => 'Fête Nationale')),
array('15.08.2014', null, array('name' => 'Assomption')),
array('01.11.2014', null, array('name' => 'La Toussaint')),
array('11.11.2014', null, array('name' => 'Armistice')),
array('25.12.2014', null, array('name' => 'Noël')),
array('2014-03-21', null, null),
array('2014-01-01', null, array('name' => 'Jour de l\'an')),
array('2014-04-21', null, array('name' => 'Lundi de Pâques')),
array('2014-05-01', null, array('name' => 'Fête du Travail')),
array('2014-05-08', null, array('name' => '8 Mai 1945')),
array('2014-05-29', null, array('name' => 'Jeudi de l\'Ascension')),
array('2014-06-09', null, array('name' => 'Lundi de Pentecôte')),
array('2014-07-14', null, array('name' => 'Fête Nationale')),
array('2014-08-15', null, array('name' => 'Assomption')),
array('2014-11-01', null, array('name' => 'La Toussaint')),
array('2014-11-11', null, array('name' => 'Armistice')),
array('2014-12-25', null, array('name' => 'Noël')),
);
}
}
20 changes: 10 additions & 10 deletions tests/Checkdomain/Holiday/Provider/ITTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ public function setUp()
public function dateProvider()
{
return array(
array('01.01.2010', null, array('name' => 'Capodanno')),
array('2010-01-01', null, array('name' => 'Capodanno')),

array('24.04.2014', null, null),
array('25.04.2014', null, array('name' => 'Liberazione dal nazifascismo (1945)')),
array('01.01.2014', null, array('name' => 'Capodanno')),
array('2014-04-24', null, null),
array('2014-04-25', null, array('name' => 'Liberazione dal nazifascismo (1945)')),
array('2014-01-01', null, array('name' => 'Capodanno')),

array('20.04.2014', null, array('name' => 'Pasqua')),
array('21.04.2014', null, array('name' => 'Lunedì di Pasqua')),
array('2014-04-20', null, array('name' => 'Pasqua')),
array('2014-04-21', null, array('name' => 'Lunedì di Pasqua')),

array('25.12.2016', null, array('name' => 'Natale di Gesù')),
array('26.12.2016', null, array('name' => 'Santo Stefano')),
array('2016-12-25', null, array('name' => 'Natale di Gesù')),
array('2016-12-26', null, array('name' => 'Santo Stefano')),

array('02.06.2016', null, array('name' => 'Festa della Repubblica')),
array('15.08.2016', null, array('name' => 'Assunzione di Maria')),
array('2016-06-02', null, array('name' => 'Festa della Repubblica')),
array('2016-08-15', null, array('name' => 'Assunzione di Maria')),
);
}
}
72 changes: 36 additions & 36 deletions tests/Checkdomain/Holiday/Provider/NOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,59 @@ public function dateProvider()
{
return array(
#Test holidays in past years
array('21.03.2010', null, null),
array('01.01.2010', null, array('name' => '1. nyttårsdag')),
array('2010-03-21', null, null),
array('2010-01-01', null, array('name' => '1. nyttårsdag')),

array('01.04.2010', null, array('name' => 'Skjærtorsdag')),
array('02.04.2010', null, array('name' => 'Langfredag')),
array('04.04.2010', null, array('name' => '1. påskedag')),
array('05.04.2010', null, array('name' => '2. påskedag')),
array('2010-04-01', null, array('name' => 'Skjærtorsdag')),
array('2010-04-02', null, array('name' => 'Langfredag')),
array('2010-04-04', null, array('name' => '1. påskedag')),
array('2010-04-05', null, array('name' => '2. påskedag')),

array('01.05.2010', null, array('name' => '1. mai')),
array('13.05.2010', null, array('name' => 'Kristi Himmelfartsdag')),
array('17.05.2010', null, array('name' => 'Grunnlovsdagen')),
array('2010-05-01', null, array('name' => '1. mai')),
array('2010-05-13', null, array('name' => 'Kristi Himmelfartsdag')),
array('2010-05-17', null, array('name' => 'Grunnlovsdagen')),

array('24.05.2010', null, array('name' => '2. pinsedag')),
array('2010-05-24', null, array('name' => '2. pinsedag')),

array('25.12.2010', null, array('name' => '1. juledag')),
array('26.12.2010', null, array('name' => '2. juledag')),
array('2010-12-25', null, array('name' => '1. juledag')),
array('2010-12-26', null, array('name' => '2. juledag')),

#Test current year, (when writing these tests)
array('21.03.2014', null, null),
array('01.01.2014', null, array('name' => '1. nyttårsdag')),
array('2014-03-21', null, null),
array('2014-01-01', null, array('name' => '1. nyttårsdag')),

array('17.04.2014', null, array('name' => 'Skjærtorsdag')),
array('18.04.2014', null, array('name' => 'Langfredag')),
array('20.04.2014', null, array('name' => '1. påskedag')),
array('21.04.2014', null, array('name' => '2. påskedag')),
array('2014-04-17', null, array('name' => 'Skjærtorsdag')),
array('2014-04-18', null, array('name' => 'Langfredag')),
array('2014-04-20', null, array('name' => '1. påskedag')),
array('2014-04-21', null, array('name' => '2. påskedag')),

array('01.05.2014', null, array('name' => '1. mai')),
array('29.05.2014', null, array('name' => 'Kristi Himmelfartsdag')),
array('17.05.2014', null, array('name' => 'Grunnlovsdagen')),
array('2014-05-01', null, array('name' => '1. mai')),
array('2014-05-29', null, array('name' => 'Kristi Himmelfartsdag')),
array('2014-05-17', null, array('name' => 'Grunnlovsdagen')),

array('09.06.2014', null, array('name' => '2. pinsedag')),
array('2014-06-09', null, array('name' => '2. pinsedag')),

array('25.12.2014', null, array('name' => '1. juledag')),
array('26.12.2014', null, array('name' => '2. juledag')),
array('2014-12-25', null, array('name' => '1. juledag')),
array('2014-12-26', null, array('name' => '2. juledag')),


#Test in the future
array('21.03.2016', null, null),
array('01.01.2016', null, array('name' => '1. nyttårsdag')),
array('2016-03-21', null, null),
array('2016-01-01', null, array('name' => '1. nyttårsdag')),

array('24.03.2016', null, array('name' => 'Skjærtorsdag')),
array('25.03.2016', null, array('name' => 'Langfredag')),
array('27.03.2016', null, array('name' => '1. påskedag')),
array('28.03.2016', null, array('name' => '2. påskedag')),
array('2016-03-24', null, array('name' => 'Skjærtorsdag')),
array('2016-03-25', null, array('name' => 'Langfredag')),
array('2016-03-27', null, array('name' => '1. påskedag')),
array('2016-03-28', null, array('name' => '2. påskedag')),

array('01.05.2016', null, array('name' => '1. mai')),
array('05.05.2016', null, array('name' => 'Kristi Himmelfartsdag')),
array('17.05.2016', null, array('name' => 'Grunnlovsdagen')),
array('2016-05-01', null, array('name' => '1. mai')),
array('2016-05-05', null, array('name' => 'Kristi Himmelfartsdag')),
array('2016-05-17', null, array('name' => 'Grunnlovsdagen')),

array('16.05.2016', null, array('name' => '2. pinsedag')),
array('2016-05-16', null, array('name' => '2. pinsedag')),

array('25.12.2016', null, array('name' => '1. juledag')),
array('26.12.2016', null, array('name' => '2. juledag')),
array('2016-12-25', null, array('name' => '1. juledag')),
array('2016-12-26', null, array('name' => '2. juledag')),
);
}
}
20 changes: 10 additions & 10 deletions tests/Checkdomain/Holiday/Provider/PLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public function setUp()
public function dateProvider()
{
return array(
array('01.01.2014', null, array('name' => 'Nowy Rok')),
array('27.03.2016', null, array('name' => 'Wielkanoc')),
array('28.03.2016', null, array('name' => 'Poniedziałek Wielkanocny')),
array('25.12.2014', null, array('name' => 'Boże Narodzenie')),
array('11.11.2013', null, array('name' => 'Święto Niepodległości')),
array('04.06.2015', null, array('name' => 'Boże Ciało')),
array('01.11.2018', null, array('name' => 'Wszystkich Świętych')),
array('01.05.2015', null, array('name' => 'Święto Pracy')),
array('26.12.2016', null, array('name' => 'Drugi dzień Bożego Narodzenia')),
array('15.08.2016', null, array('name' => 'Wniebowzięcie Najświętszej Maryi Panny')),
array('2014-01-01', null, array('name' => 'Nowy Rok')),
array('2016-03-27', null, array('name' => 'Wielkanoc')),
array('2016-03-28', null, array('name' => 'Poniedziałek Wielkanocny')),
array('2014-12-25', null, array('name' => 'Boże Narodzenie')),
array('2013-11-11', null, array('name' => 'Święto Niepodległości')),
array('2015-06-04', null, array('name' => 'Boże Ciało')),
array('2018-11-01', null, array('name' => 'Wszystkich Świętych')),
array('2015-05-01', null, array('name' => 'Święto Pracy')),
array('2016-12-26', null, array('name' => 'Drugi dzień Bożego Narodzenia')),
array('2016-08-15', null, array('name' => 'Wniebowzięcie Najświętszej Maryi Panny')),
);
}
}
Loading

0 comments on commit 5c136b8

Please sign in to comment.