Swiftpack.co - MaxHaertwig/SwiftyHolidays as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by MaxHaertwig.
MaxHaertwig/SwiftyHolidays 1.0.0
A swifty library to determine whether a date is a holiday in a given country.
โญ๏ธ 16
๐Ÿ•“ 1 year ago
.package(url: "https://github.com/MaxHaertwig/SwiftyHolidays.git", from: "1.0.0")

๐Ÿ“… SwiftyHolidays

A swifty library for checking whether a given Date is a holiday in a specific country or state. It can also generate a list of holidays in a given year.

๐Ÿ“ฑ Example Project

Feel free to take a look at SwiftyHolidays Example to get a better feeling of how to use this library.

โš™๏ธ Installation

Xcode Project

Open your project in Xcode, click File > Swift Packages > Add Package Dependency and enter https://github.com/MaxHaertwig/SwiftyHolidays.git.

Swift Package

Open Package.swift and add the package to your project's dependencies:

let package = Package(
    ...
    dependencies: [
        ...
        .package(url: "https://github.com/MaxHaertwig/SwiftyHolidays.git", from: "1.0.0")
    ]
)

๐Ÿ“ Usage

LocalDate

The class LocalDate is used to abstract away the concept of time and time zones. LocalDate can be converted to Date and the other way around.

import SwiftyHolidays

let independenceDay = LocalDate(2020, .july, 4)!
>>> independenceDay.isHoliday(in: .unitedStates)
true
>>> independenceDay.isHoliday(in: .germany)
false

let cesarChavezDay = LocalDate(2020, .march, 31)!
>>> cesarChavezDay.isHoliday(in: .unitedStates(state: .california))
true
>>> cesarChavezDay.isHoliday(in: .unitedStates(state: .michigan))
false

let holiday = cesarChavezDay.getHoliday(in: .unitedStates(state: .california))
>>> holiday?.name
"Cรฉsar Chรกvez Day"
>>> holiday?.date
SwiftyHolidays.LocalDate(year: 2020, month: 3, day: 31)
>>> cesarChavezDay.getHoliday(in: .unitedStates(state: .michigan))
nil

>>> LocalDate.asDate(in: TimeZone(abbreviation: "PST")!)
2020-03-31 07:00:00 +0000

Swift's Date class can also be used. The related methods require a TimeZone to interpret the date. If left unspecified, the default time zone for the given country (or state) will be used.

import SwiftyHolidays

let independenceDayUTC = Date(timeIntervalSince1970: 1562198400)
>>> independenceDayUTC.isHoliday(in: .unitedStates(state: .california))
false
>>> independenceDayUTC.isHoliday(in: .unitedStates(state: .california), timeZone: TimeZone(abbreviation: "GMT")!)
true

>>> independenceDayUTC.asLocalDate(in: TimeZone(abbreviation: "GMT")!)
SwiftyHolidays.LocalDate(year: 2019, month: 7, day: 4)
>>> independenceDayUTC.asLocalDate(in: TimeZone(abbreviation: "PST")!)
SwiftyHolidays.LocalDate(year: 2019, month: 7, day: 3)

An instance of Country or CountryWithState can be initialized to generate a list of its holidays.

import SwiftyHolidays

>>> Country.germany.allHolidays(in: 2020)
>>> Country.germany.allHolidays(in: 2020..<2030)
>>> CountryWithState.germany(state: .berlin).allHolidays(in: 2020)

๐ŸŒ Supported Countries

  • Austria ๐Ÿ‡ฆ๐Ÿ‡น
  • Denmark ๐Ÿ‡ฉ๐Ÿ‡ฐ
  • France ๐Ÿ‡ซ๐Ÿ‡ท
  • Germany ๐Ÿ‡ฉ๐Ÿ‡ช
  • Italy ๐Ÿ‡ฎ๐Ÿ‡น
  • Luxembourg ๐Ÿ‡ฑ๐Ÿ‡บ
  • Spain ๐Ÿ‡ช๐Ÿ‡ธ
  • Switzerland ๐Ÿ‡จ๐Ÿ‡ญ
  • United States ๐Ÿ‡บ๐Ÿ‡ธ

You can also call Country.availableCountries to get a list of supported countries.

๐Ÿค Contributions

Feedback, Issues, and Pull Requests are always welcome.

๐Ÿ“„ License

SwiftyHolidays is released under the MIT license. See LICENSE for more information.

GitHub

link
Stars: 16
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.0: Initial Release
4 years ago

The first release of SwiftyHolidays!

It supports the holidays of Austria, Denmark, France, Germany, Luxembourg, Spain, Switzerland, and the United States.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics