Download the PHP package codemonauts/craft-holidays without Composer
On this page you can find all versions of the php package codemonauts/craft-holidays. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codemonauts/craft-holidays
More information about codemonauts/craft-holidays
Files in codemonauts/craft-holidays
Package craft-holidays
Short Description Craft CMS plugin for international holidays.
License MIT
Informations about the package craft-holidays
International holidays plugin for Craft CMS
A plugin for Craft CMS that provides access to many international holidays.
This plugin is based on the awesome work of yasumi. Go and buy him a coffee!
Background
This plugin provides easy access to holidays in many countries. For example to automatically determine if a shop or restaurant is open or closed on an official holiday in a country.
Coverage
Currently 35 countries and 85 sub-regions:
Australia, Austria, Belgium, Bosnia & Herzegovina, Brazil, Croatia, Czechia, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Italy, Japan, Latvia, Lithuania, Netherlands, New Zealand, Norway, Poland, Portugal, Romania, Russia, Slovakia, South Africa, South Korea, Spain, Sweden, Switzerland, United States, Ukraine and United Kingdom
For more details see yasumi's feature page. And if you are missing your country, why not contribute by adding a new provider for your country?
Requirements
- Craft CMS >= 4.0.0
Installation
Open your terminal and go to your Craft project:
Switch to the settings page in the control panel and enter select your default country and subregion.
Usage
You can query for holidays like for entries:
or same in php:
Filtering
You can combine the following filters in any order:
type(typename)
specifies the type of holidays to return. Default is Null
. Possible other types are:
- 'official'
- 'observance'
- 'season'
- 'bank'
- 'other'
- Null (means "all")
country(code)
sets the country for which the holidays should be returned. The code is the ISO 3166-2 code of the country and its subregion. You can set the default country in the settings.
locale(code)
sets the locale code to translate the holidays names to. The default is set to your site locale in Craft CMS.
year(year)
specifies for which year the holidays are returned. You can only get the holidays for one specific year. This is set automatically to the date set by on()
or between()
. Normally you do not need to specify anything here.
on(date)
sets a single date to check for holidays. You can provide a DateTimeInterface or a date string like '2019-12-25' or a string that can be parsed by strtotime.
between(startDate, endDate)
filter for a time range. Same rules as for on(date)
.
Fetching
To fetch the results you have different functions:
one()
returns the first holiday as an extended DateTime object (see results).
all()
returns all holidays as array (actually an iterator) of extended DateTime objects.
count()
returns the number of holidays found.
isHoliday()
returns true or false if a holiday exists.
Results
As result you get a DateTime object with the following extensions:
getType()
returns the type of holiday.
getName()
returns the translated name of the holiday. If for the given locale no translation is defined, the name in 'en_US' is returned.
Examples
Get all holidays of a year:
Get all official holidays of a time range:
Check if today is a official holiday in Japan:
Settings
You can set the default country and subregion in a config file placed in your CraftCMS config directory. You can find the most recent version in src/config.php. You have to name the file holidays.php
.
If you do not set a default country code or the country code could not be found, we fall back to US
.
With ❤ by codemonauts