Skip to content

Commit

Permalink
Merge pull request #7 from PanderMusubi/yearrange
Browse files Browse the repository at this point in the history
year range support
  • Loading branch information
commenthol authored Jan 2, 2025
2 parents c9bd93b + 3097ab8 commit 2fe92f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bin/holidays-ical.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const cmmds = {
help: ['-h', '--help', false, 'this help'],
version: ['-v', '--version', false, 'display version'],
out: ['-o', '--out', 'file' , 'write to file'],
year: ['-y', '--year', 'year', 'year'],
year: ['-y', '--year', 'year', 'year or year range'],
fullday: ['-f', '--fullday', false, 'ical events are per full day'],
showcode: ['-s', '--showcode', false , 'show country code in each ical summary'],
transp: ['-t', '--transp', false, 'ical events are all transparent'],
Expand Down Expand Up @@ -49,6 +49,9 @@ const cli = (cmmds, argv = process.argv.slice(2)) => {
Calender for 2017 New Zealand Auckland Province:
$ holiday-ical -f -y 2017 NZ.au
Calender for 2017 - 2019 New Zealand Auckland Province:
$ holiday-ical -f -y 2017-2019 NZ.au
`
while (argv.length) {
const arg = argv.shift()
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ function ical (opts) {

/**
* Convert to iCal Calendar
* @param {Number} [year]
* @param {String} [year]
* @param {Object} [opts]
* @return {String} iCal formatted Calendar
*/
calendar: function (year, opts) {
const dates = hd.getHolidays(year)
let dates = []
if (year.includes('-')) {
const [start, end] = year.split('-').map(Number)
for (let tmp = start; tmp <= end; tmp++) {
dates = dates.concat(hd.getHolidays(tmp))
}
} else {
dates = hd.getHolidays(year)
}

if (dates) {
if (opts.name || opts.showcode) {
Expand Down

0 comments on commit 2fe92f8

Please sign in to comment.