Download the PHP package umulmrum/holiday without Composer

On this page you can find all versions of the php package umulmrum/holiday. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package holiday

Holiday

Holiday is a library that computes holidays in a very flexible way. It is possible to filter holiday lists by various criteria and format them in different ways. It is easy to add more holiday providers, filters and formatters, so even if this library does not perfectly fit your needs, you can simply extend it.

Latest Stable Version Latest Unstable Version License

Requirements

That's it really.

Installation

Install the library using Composer.

Usage Examples

Simple example:

This results in a HolidayList which contains all holidays for 2020; this list can then be used for output or further computation. Holidays are always computed for one full year and can then be narrowed down using filters.

More complex example:

This results in an array of date strings. Note that we used the ISO-3166-2 code DE-BY to get the holidays for Bavaria. See section Resolving Holiday Providers below for different ways to request holidays.

There are also some helper methods that simplify some common holiday computations. Using the GetHolidayForMonth helper, the example above can be substituted by this:

One last example shows how to compute all holidays, Saturdays and Sundays in the years 2020 and 2021 for the German state Baden-Wuerttemberg, sort these holidays by date and format the result as JSON (all in 2 lines of code):

Detailed Usage

First create a HolidayList for holidays in one or more years by using the HolidayCalculator. Pass one or more holiday providers to the calculator to get holidays for these providers, e.g. a country, a religion or event a specific weekday. HolidayList is basically an augmented array of Holiday objects.

See the complete list of built-in providers under src/Provider or use them as examples to create your own. Be aware that a holiday is NOT equivalent to a day off - holidays in the sense of this lib is more of a "special day" as defined by providers, and might be traditional or religious days without impact on working hours. To restrict a HolidayList to days off, use the IncludeTypeFilter as described below in the Filters section.

The HolidayList can then be asked for information or holidays can be added or removed, the list can be filtered or formatted.

Resolving Holiday Providers

The examples above already showed two different ways to specify for which region or other "entity" holidays should be calculated. There is also a third way, and complete customization is also possible - let's have a look at all of them:

  1. Fully qualified class name:

    This is suggested as default, since you only need to remember the region to request and IDEs should provide autocompletion to save keystrokes.

  2. Instantiated class:

    Use an instantiated class of the same type as you would specify when using way 1. Do this if a provider has constructor arguments, such as additional holiday types as seen in the example (Sundays aren't automatically days off).

  3. ISO-3166 names:

    Use ISO-3166-1 country codes or ISO-3166-2 region codes e.g. if your application already uses them to simplify integration and decoupling of the Holiday lib. The list of supported countries and regions can be found in src/Resolver/isoData.php. There is a fallback to the base country in case the region code is not found - see the comment in the IsoResolver class for details.

  4. Custom

    Use this to add custom resolving logic. ResolverHandler takes an array of ProviderResolverInterfaces (and implements ResolverHandlerInterface, so can even be exchanged with more custom code).

Filters

Use filters to narrow down the list of holidays to the desired subset.

See the complete list of built-in filters under src/Filter or use them as examples to create your own (extend AbstractFilter or implement HolidayFilterInterface).

Formatters

Use formatters to - you guessed it - format HolidayLists and Holidays.

Formatters may return a string or an array of strings.

See the complete list of built-in formatters under src/Formatter or use them as examples to create your own (implement HolidayFormatterInterface).

Holiday Types

A HolidayList contains Holiday objects. Apart from a (technical) name and date, each holiday has one or more types. Return these types as an integer bit mask by calling Holiday::getType(), or ask for specific types using Holiday::hasType().

The type is normally a combination of

See the HolidayType class for available types. This class also contains translation keys for these types which can then get translated for localized readable names - see e.g. JsonFormatter for details.

Which Holidays are Returned

HolidayCalculator only returns holidays that are legally defined in the scope of the chosen holiday provider, or if there's "secular impact", e.g. it's a day off. This means there are differences between providers; e.g. Easter Sunday is an official holiday in Brandenburg/Germany, so it is included for Brandenburg. In the rest of Germany (as well as most other countries) it is not a holiday as it is a Sunday anyway, and therefore not included as a holiday.

Similarly, Sundays are normally not included if they are no official holidays in the scope of the holiday provider, although they are days off in the Western hemisphere. To find out which days are days off, provide both the respective holiday provider and the one for Sundays (or use GetNoWorkDaysForTimeSpan()).

If your use case requires other holiday lists, consider combining multiple providers (e.g. Switzerland and ChristianHolidays), or remove some using filters (e.g. combine IncludeTypeFilter and InverseFilter) to remove Sundays from Brandenburg lists.

Translations

Some formatters can be initialized with an optional translator. See TranslatorInterface and the translation files under res/trans.

Helpers

To simplify some common holiday-related tasks, see the helpers under src/Helper (e.g. the GetNoWorkDaysForTimeSpan helper takes holiday providers and a timespan and calculates a list of all days off for these arguments).

Supported Calendars

Currently only the Gregorian calendar is supported, for years < 10000.

Supported Countries

(map created by simplemaps.com - licensed under MIT)

To create your own holiday providers have a look at the existing code, it should be self-explanatory. I will happily merge pull requests to support more countries (see below).

Notes on German Holidays

Notes on Swiss Holidays

Notes on Christian Holidays

Note on Holidays Way in the Past or Future

If computing holidays for past years, be aware that they may not be accurate. All holidays were introduced at some point in time, so this lib might return holidays for years in which they really were not in existence, as well as omit holidays that haven't been celebrated for a long time.

Likewise holidays might of course change in the future. Also, Easter date calculation will change in the far future due to astronomical reasons.

This lib aims to be accurate for "recent" years at least, approximately for years after World War II until present. Again, contributions are welcome.

Versioning

This library follows Semantic Versioning. Everything in the library can be considered the public API except:

Contribution

Contributions are highly welcome. Please follow these rules when submitting a PR:

By submitting a PR you agree that all your contributed code may be used under the MIT license.

How To Add a New Country or Region

License

Holiday is licensed under the MIT License. See LICENSE for details.

In short, this license allows you to use this code for almost anything you like. If you somehow make use of it to suppress, injure, kill, spy, or any other thing considered evil, there is nothing in this license that holds you back. But fuck you anyway.

For all other people I hope this little lib helps you and perhaps even gives you some pleasure.


All versions of holiday with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package umulmrum/holiday contains the following files

Loading the files please wait ....