An offline database with APIs to check if a given date is on a public holiday for a given region.
Contains public holidays of over 100 countries from start of 2020 to end of 2029.
This library basically has just two main functions and two supporting functions.
Here's how to use the main functions:
// First main function returns list of public holidays for a given location: try PublicHolidays.all(countryCode: "US") // => [PublicHoliday(localName: "New Year's Day", date: "2020-01-01"), ...] try PublicHolidays.all(countryCode: "US", subTerritoryCode: "DC") // => [PublicHoliday(localName: "New Year's Day", date: "2020-01-01"), ...] // Second main checks if a given date is on a public holiday for a given location: try PublicHolidays.contains(date: Date(), country: "FR") // => true/false try PublicHolidays.contains(date: Date(), country: "GB", subTerritoryCode: "ENG") // => true/false
subTerritoryCode is optional and has a default value of
PublicHoliday consists of a
localName: String and a
date: Date. Technically speaking, you can also specify a custom
timeZone to use when loading the public holidays, but it is discouraged to do that unless you really know what you're doing. By default, the calculation will be using the current time zone of the device so passing a
timeZone shouldn't be necessary in most cases.
If you provide a
countryCode or a
subTerritoryCode for which no data is available in this library, the method will throw an error. To prevent this, there are two supporting functions that tell you for which data is available:
PublicHolidays.availableCountries() // => ["US", "DE", "JP", "FR", ...] try PublicHolidays.availableSubTerritories(countryCode: "GB") // => ["ENG", "NIR", "SCT", "WLS"]
PublicHolidays was brought to you by Cihat Gündüz in his free time. If you want to thank me and support the development of this project, please make a small donation on PayPal. In case you also like my other open source contributions and articles, please consider motivating me by becoming a sponsor on GitHub or a patron on Patreon.
Thank you very much for any donation, it really helps out a lot! 💯
Contributions are welcome. Feel free to open an issue on GitHub with your ideas or implement an idea yourself and post a pull request. If you want to contribute code, please try to follow the same syntax and semantic in your commit messages (see rationale here). Also, please make sure to add an entry to the
CHANGELOG.md file which explains your change.
To update the public holidays data JSON files from nager.date API, run this command from project root:
swift build && .build/x86_64-apple-macosx/debug/PublicHolidaysUpdater
This library is released under the MIT License. See LICENSE for details.