SwiftyHolidayUtil 0.1.1

SwiftyHolidayUtil 0.1.1

Maintained by Kazuo Matsunaga.




SwiftyHolidayUtil

Version License Platform

About

SwiftyHolidayUtil is a library for highlighting holidays.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swit 4.2

Installation

SwiftyHolidayUtil is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftyHolidayUtil'

Usage

Very easy as it can be used as extension of UILabel.

import SwiftyHolidayUtil

let label:UILabel = UILabel()
label.frame = CGRect(x: 0, y: 0, width: 200, height: 20)
label.date = Date()

If the locale of your device is "en_US", it is displayed as follows.

2019-01-28 22 36 13

DateStyle

SwiftyHolidayUtil.dateStyle

dateStyle
.short
.medium (default)
.long
.custom(customFormat:String)
label.dateStyle = .short
label.date = Date()

2019-01-28 22 44 20

label.dateStyle = .long
label.date = Date()

2019-01-28 22 46 00

Locale

label.locale = Locale(identifier: "ja_JP")
label.dateStyle = .long
label.date = Date()

2019-01-28 22 49 47

label.locale = Locale(identifier: "ja_JP")
label.dateStyle = .mediunm
label.date = Date()

2019-01-28 22 50 36

Options

SwiftyHolidayUtil.holidayFormatOptions

FormatOptionKey value
.holidayColor UIColor or HexString (ex. "#FF0000")
.saturdayColor UIColor or HexString
.sundayColor UIColor or HexString
.weekSymbolType WeekSymbolType.standalone / .short / .veryshort
.weekPosision WeekPosition.head / .tail
.shortWeekPrefix String : Prefix of week string at long date style
.shortWeekSuffix String : Suffix of week String at short date style
.mediumWeekPrefix String : Prefix of week String at medium date syle
.mediumWeekSuffix String : Suffix of week String at short date Style
.longWeekPrefix String : Prefix of week String at long date Style
.longWeekSuffix String : Suffix of week String at long date Style
.timeStyle TimeStyle.long / .medium / .short / .none(default) / .full / .custom(customFormat: String)
label.locale = Locale(identifier: "ja_JP")
label.dateStyle = .mediunm
label.holidayFormatOptions = [
            .holidayColor: "#077705",
            .mediumWeekPrefix: "",
            .mediumWeekSuffix: "",
            .weekPosision: SwiftyHolidayUtil.WeekPosition.head
        ]
label.date = Date()

2019-01-28 23 41 09

Color of Day

In my country Japan, We express blue on Saturday and red on Sundays and holidays. In your country, what color do you express on Saturdays, Sundays and holidays?

Please pull request region code and colors.

  • HolidayUtil+defaulRegionOptions.swift
"JP": [
            FormatOptionKey.saturdayColor: UIColor.blue,
            FormatOptionKey.sundayColor: UIColor.red,
            FormatOptionKey.holidayColor: UIColor.red
        ]

Holidays calculation logic

Currently it is implemented only in Japan's holiday calculation logic.

fumiyasac/handMadeCalendarOfSwift

US, Korea, Vietnam have implemented provisional logic. However, it is incomplete which can only calculate the holiday of 2019. If you have perfect logic in your country, please implement and pull request.

Author

kazuomatz, [email protected]

License

SwiftyHolidayUtil is available under the MIT license. See the LICENSE file for more info.