Skip to content

Commit

Permalink
Merge 4c12f39 into 6060508
Browse files Browse the repository at this point in the history
  • Loading branch information
heiglandreas committed Oct 13, 2022
2 parents 6060508 + 4c12f39 commit 819ca54
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 12 deletions.
50 changes: 48 additions & 2 deletions README.md
Expand Up @@ -162,5 +162,51 @@ a lot of different factors.
To not lead people into false expectations and use amagic that will bite back rather sooner than later I decided to
not implement this in the library but leave that to your business-logic.

I might at a future time implement something that you can use to calculate business-days but that will for sure
require some business-logic related code to work properly.
To give you an idea how such a feature could look like I wrote an example that show that most of the required code is
actually business-case related or required for setup. Only three lines are related to this library. So having
a dedicated class for that in this library doesn't seem to make sense.

```php
<?php
/**
* Copyright Andreas Heigl <andreas@heigl.org>
*
* Licenses under the MIT-license. For details see the included file LICENSE.md
*/

use Org_Heigl\Holidaychecker\Holidaychecker;
use Org_Heigl\Holidaychecker\HolidayIteratorFactory;

$factory = new HolidayIteratorFactory();
$iterator = $factory->createIteratorFromISO3166('DE');
$checker = new Holidaychecker($iterator);

$startDate = new DateTimeImmutable('2022-10-10');
$endDate = new DateTimeImmutable('2022-10-31');
$dateIterator = new DatePeriod(
$startDate,
new DateInterval('P1D'),
$endDate
);

$numberOfBusinessDays = 0;

foreach ($dateIterator as $date) {
if ($checker->check($date)->isHoliday()) {
continue;
}

// Your business-Logic here
// This is where the magic actually happens.
// Whether you count only sundays.
// Or saturdays AND sundays or whatever else your general days off are!
$numberOfBusinessDays++;
}

echo sprintf(
'There are %1$d business-days between %2$s and %3$s',
$numberOfBusinessDays,
$startDate->format('d.m.Y'),
$endDate->format('d.m.Y'),
);
```
44 changes: 34 additions & 10 deletions docs/index.md
Expand Up @@ -4,11 +4,11 @@ title: "holidayChecker"
permalink: /
---

This library allows you to check a single day against one or multiple calendars
This library allows you to check a single day against one or multiple calendars
to see whether the given day is a holiday or not.

That also includes "named Days" that are not necessarily "free" but have a special
name like "Maundy Thursday".
That also includes "named Days" that are not necessarily "free" but have a special
name like "Maundy Thursday".

## Installation

Expand All @@ -35,10 +35,10 @@ $result has 3 methods:

* **isHoliday** is ```true``` when the day is a free day according to the local law. Otherwise it's ```false```
* **isNamed** is ```true``` when the day has a special name despite being not a free day.
* **getName** contains the name of a named day.
* **getName** contains the name of a named day.

You can also get a ```HolidayIterator``` with a 2-letter [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1)
or a 4-letter [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) code. And when different language-variations are available you can get them
or a 4-letter [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) code. And when different language-variations are available you can get them
by adding the [ISO 639-1 language-code](https://en.wikipedia.org/wiki/ISO_3166-2) before the ISO 3166-code:

```php
Expand All @@ -56,31 +56,55 @@ $iterator = $factory->createIteratorFromIso3166('fr_BE');

Currently the holidays for these countries are available:

![Map of the world](world.svg)

* Germany (all Bundesländer, german)
* Luxemburg (german, french and luxembourgisch)
* Belgium (flamisch and french)
* Netherlands (dutch)
* France (Mainland and overseas, adaptions for Elsass/Lothringen, french)
* United Kingdom (Islands, Walse, Scotland, Northern Ireland and England, englisch)
* United Kingdom (Islands, Wales, Scotland, Northern Ireland and England, englisch)
* Finland
* Russia
* Greece
* Turkey
* Russia
* South Africa (english)
* Ireland (english and irish)
* Spain (all provinces, spanish)
* Portugal (mainland, Madeira and Azores, portuguese)
* Denmark (danish)
* Sweden (swedish)
* Norway (bokmål)
* Poland (polish)
* Austria (german)
* Italy (italian)
* Canada (french and english)
* United States (Federal holidays only - english)
* Brazil (brazilian portuguese)
* Japan (needs better way to handle Equinoxes)
* Chinese (Needs better way to handle solar terms)
* Afghanistan (english)
* Albania (Albanian)
* Algeria (English)
* Andorra (all parishes)
* Angola
* Antigua and Barbuda

But the list is constantly extending.

## Extending

Currently not all countries holidays are available. We are trying to fix that
Currently not all countries holidays are available. We are trying to fix that
but you might find that exactly the country you need is missing.

As the holidays are retrieved from XML-files you can add your own ones without
As the holidays are retrieved from XML-files you can add your own ones without
issue. They need to correspond to the [Schema-file](https://www.heigl.org/xml/xsd/holidays.xsd)
and before the schema is checked any XInclude-statements are executed. For more
information on that have a look at the [more detailed description](extend_xml)

You can then load the holidays from your file using the ```createIteratorFromXmlFile```-method.

If you think the XML-files might be usefull for others you should think about
If you think the XML-files might be usefull for others you should think about
contributing back and open a PullRequest here or attach them to an issue you open.

We'd be very thankfull!

0 comments on commit 819ca54

Please sign in to comment.