DLDHolidays

main

A Swift wrapper for the Nager.Date API, providing a simple interface to fetch and work with public holiday data in your apps.
diliedevs/DLDHolidays

DLDHolidays

Swift Version Apple Platforms GitHub Tag GitHub Contact

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.

Features

  • Async/await Swift wrapper around the Nager.Date v3 endpoints via a simple Holidays service.
  • 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, and HolidayType.
  • 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) and Sendable models.
  • Models conform to Codable, Sendable, Identifiable, and Hashable via a shared Model alias.
  • No third-party dependencies; distributed as a Swift Package.
  • Multi-platform support: iOS 16+, macOS 13+, tvOS 16+, watchOS 9+.

Installation

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

Usage

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)")
    }
}

Credits

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.

License

DLDHolidays is available under the MIT license, which permits commercial use, modification, distribution, and private use. See the LICENSE file for more info.

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Jan 24 2026 03:10:30 GMT-1000 (Hawaii-Aleutian Standard Time)