Swift 库,用于处理东方和德国的节假日(固定到各州,而不是)。
要使用 CocoaPods 将 SSHolidays 集成到您的 Xcode 项目中,请在 Podfile 中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TargetName' do
pod 'SSHolidays', '1.0'
end
然后,运行以下命令
$ pod install
节假日
isHolidayByDate
isHolidayByComponents
holidaysBetweenDates
name
year
month
day
date
fixedWithState
states
weekday
首先您需要导入主类
import SSHolidays
name
A String
representing the holiday’s name. This is mostly in english, but all german holidays are in german for obvious reasons.
year
Int
representing the holiday’s year.
month
Int
representing the holiday’s month.
day
Int
representing the holiday’s day.
date
NSDate
representing the holiday’s date as a NSDate object.
fixedWithState
Bool
representing if a holiday is fixed to a german state.
states
Array<String>
containing all states fixed to this holiday (empty if non fixed)
weekday
Int
representing the holiday’s weekday.
holidaysBetweenDates
要检查两个日期之间是否有假日,请调用 Holidays.holidaysBetweenDates
。这将返回一个包含您请求期间 Holiday
对象的数组。
let date1 = NSDate()
let dateComponents: NSDateComponents = NSDateComponents()
dateComponents.year = 2016
dateComponents.month = 12
dateComponents.day = 30
let date2 :NSDate = NSCalendar.currentCalendar().dateFromComponents(dateComponents)!
let holidaysInBetween = Holidays.holidaysBetweenDates(fromDate: date1, toDate: date2)
holidays
要检查某一年份的假日,只需调用 Holidays.holidays
并传递请求年份的 Int
参数。这将返回一个包含请求年份 Holiday
对象的数组。
let holidays2016 = Holidays.holidays(year: 2016)
isHolidayByDate
要检查某个特定日期(通过 NSDate
)是否为假日,请调用 Holidays.isHolidayByDate
。这将返回一个布尔值。
if Holidays.isHolidayByDate(date: NSDate()) {
print("This may be first christmas day")
}
isHolidayByComponents
要检查某个特定日期(通过日期组件)是否为假日,请调用 Holidays.isHolidayByComponents
。这将返回一个布尔值。
if Holidays.isHolidayByComponents(year: 2016, month: 12, day: 25) {
print("This is first christmas day")
}
SSHolidays 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。