GithubHelp home page GithubHelp logo

icesco / swiftyholidays Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxhaertwig/swiftyholidays

0.0 0.0 0.0 66 KB

A swifty library to determine whether a date is a holiday in a given country.

License: MIT License

Swift 100.00%

swiftyholidays's Introduction

๐Ÿ“… 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.

swiftyholidays's People

Contributors

icesco avatar maxhaertwig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.