@ 日期/ holidays- us
A 类 @date/holidays 例如美国公共假日和银行假日.
也有计算特定节假日日期的职能.
安装
npm install @date/holidays-us --save
使用量
// get Holidays instance with both public and bank holidays
var holidays = require('@date/holidays-us')
var date = new Date(2016, 0, 1) // New Year's Day 2016
holidays.isHoliday(date) // true
date.setDate(10) // January 10th 2016
holidays.isHoliday(date) // false
date = holidays.thanksgiving(2015) // November 26th, 2015
date = holidays.thanksgiving(2016) // November 24th, 2016
date = holidays.valentinesDay(2016) // February 14th, 2016
holidays.isHoliday(date) // true, it's a holiday
// this will return false because Valentine's Day isn't a bank holiday
holidays.isHoliday(date, {
// only consider it a holiday when the properties in this object match
bank:true // must be a bank holiday
})
只有银行假日
// this has only the bank holidays, not the 'public' ones
var holidays = require('@date/holidays-us').bank()
// returns false, Valentine's isn't a bank holiday
holidays.isHoliday(new Date(2016, 1, 14))
// returns true, New Year's is a bank holiday
holidays.isHoliday(new Date(2016, 0, 1))
只有公共假日
// this has only the non-bank holidays
var holidays = require('@date/holidays-us').public()
// returns true, Valentine's is a public holiday
holidays.isHoliday(new Date(2016, 1, 14))
// returns false, because New Year's is a bank holiday
holidays.isHoliday(new Date(2016, 0, 1))
// NOTE: technically, I suppose the bank holidays are also
// public holidays, but, if you want both, use the default
// instance which has both
API: 发电机
根据特定年份产生特定假日的职能:
- new Years Day() - 也可以计算所观察到的假日
- 情人节( )
- 马丁·卢瑟金日( )
- 主席日( )
- 东( )
- 母亲日( )
- 纪念日( )
- 父亲日( )
- 独立日( ) - 也可以计算所观察的节日
- 劳动日( )
- 连发日( )
- 圣灵 ()
- 退伍军人日( ) - 也可以计算所观察的假日
- 感恩节 ()
- 圣诞节( ) - 也可以计算所观察到的假日
API:观察假日
有些节日与节日不同时被"观察". 生成函数也可以计算出来.
var holidays = require('@date/holidays-us')
// Christmas in 2016 is on a Sunday so it is "observed" the next day, Monday.
// the call to the generator returns the date instance as expected
var christmasDay = holidays.christmas(2016) // same as new Date(2016, 11, 25)
// it also has an `observed` property containing the "observed" holiday date
// Note: if there is no "observed" holiday then `observed` is undefined
var observedChristmas = date.observed
// christmas == new Date(2016, 11, 25) Sunday, December 25th 2016
// observedChristmas == new Date(2016, 11, 26) Monday, December 26th 2016