DLDHolidays is a Swift wrapper for the Nager.Date API, providing a simple interface to fetch and work with public holiday data in your apps.
- Async/await Swift wrapper around the Nager.Date v3 endpoints via a simple
Holidaysservice. - Endpoints supported:
- List available countries
- Fetch public holidays for a given year and country
- Fetch the next upcoming public holidays for a country
- Fetch long weekends for a given year and country (including bridge-day info)
- Check if today is a public holiday for a country
- Strongly typed models:
Country,PublicHoliday,LongWeekend, andHolidayType. - Lightweight
URLSession-based client that validates HTTP responses and decodes JSON. - Clear error handling with
APIError(invalid URL, request failed with status code, decoding failed). - Sensible defaults for date handling (
yyyy-MM-dd) and JSON decoding. - Concurrency-first design using Swift actors (
APIClient) andSendablemodels. - Models conform to
Codable,Sendable,Identifiable, andHashablevia a sharedModelalias. - No third-party dependencies; distributed as a Swift Package.
- Multi-platform support: iOS 16+, macOS 13+, tvOS 16+, watchOS 9+.
Add this library to your project by using the Swift Package Manager.
Go to File > Add Packages… and enter the following URL:
https://github.com/diliedevs/DLDHolidays.git
Click on the Copy Dependency button.
Import the package into your files.
import DLDHolidays
Import the package and use the Holidays service with async/await:
import DLDHolidays
let holidays = Holidays()
Task {
do {
// List available countries
let countries = try await holidays.availableCountries()
print("Loaded \(countries.count) countries")
// Fetch public holidays for the current year in the US
let year = Calendar.current.component(.year, from: Date())
let usHolidays = try await holidays.publicHolidays(year: year, countryCode: "US")
let formatter = DateFormatter()
formatter.dateStyle = .medium
for holiday in usHolidays {
let types = holiday.types.map(\.name).joined(separator: “, “)
print(“\(formatter.string(from: holiday.date)) — \(holiday.localName) [\(types)]”)
}
// Long weekends
let longWeekends = try await holidays.longWeekend(year: year, countryCode: "US")
print("Long weekends this year: \(longWeekends.count)")
// Is today a public holiday?
let isTodayHoliday = try await holidays.isTodayPublicHoliday(countryCode: "US")
print("Is today a public holiday? \(isTodayHoliday)")
} catch let apiError as APIError {
switch apiError.kind {
case .invalidURL:
print("Invalid URL")
case .requestFailed(let status):
print("Request failed with status \(status)")
case .decodingFailed(let data):
print("Decoding failed: \(String(data: data, encoding: .utf8) ?? "<non-UTF8 body>")")
}
} catch {
print("Unexpected error: \(error)")
}
}DLDHolidays was made by Dionne Lie Sam Foek.
And of course credit to the people who created the Nager.Date API and provide all the data.
DLDHolidays is available under the MIT license, which permits commercial use, modification, distribution, and private use. See the LICENSE file for more info.