Skip to content

Commit

Permalink
Merge pull request #6 from PanderMusubi/extension
Browse files Browse the repository at this point in the history
option to force all events transparent
  • Loading branch information
commenthol authored Jan 2, 2025
2 parents 59783a0 + fcc92fe commit c9bd93b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bin/holidays-ical.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const cmmds = {
out: ['-o', '--out', 'file' , 'write to file'],
year: ['-y', '--year', 'year', 'year'],
fullday: ['-f', '--fullday', false, 'ical events are per full day'],
showcode: ['-s', '--showcode', false , 'show country code in each ical summary'],
showcode: ['-s', '--showcode', false , 'show country code in each ical summary'],
transp: ['-t', '--transp', false, 'ical events are all transparent'],
name: ['-n', '--name', 'name', 'instead of country code add your own name to each ical summary'],
query: ['-q', '--query', false, 'query for available countries, states, regions by shortcode'],
language: ['-l', '--language', 'language', 'set language']
Expand Down Expand Up @@ -90,7 +91,7 @@ function main (cmd) {
res = ical.init.call(null, country, state, region, opts)
if (res) {
const opts = {}
;['name', 'showcode', 'fullday'].forEach(function (p) {
;['name', 'showcode', 'fullday', 'transp'].forEach(function (p) {
if (/string|boolean/.test(typeof cmd[p])) {
opts[p] = cmd[p]
}
Expand Down
3 changes: 2 additions & 1 deletion src/vcalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function toDay (str, offset = 0) {
* @param {Object} date
* @param {Object} [opts]
* @param {Boolean} [opts.fullday] - if `true` then event is treated to be on complete day
* @param {Boolean} [opts.transp] - if `true` then event is treated to be always transparent
* @return {String} a single vCalendar vevent
*/
function vevent (date, opts = {}) {
Expand All @@ -98,7 +99,7 @@ function vevent (date, opts = {}) {
dtstart: dtstart,
dtend: dtend,
description: type + (type && note ? ' - ' : '') + note,
busy: type === 'public',
busy: !opts.transp && type === 'public',
uid: uid()
}

Expand Down
22 changes: 22 additions & 0 deletions test/index.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ END:VCALENDAR
assert.strictEqual(comp(res), comp(exp))
})

it('can generate a calendar without one fullday entry and force time as free (transparent)', function () {
const res = vcalendar([].concat(dates[0]), { fullday: 1, transp: 1 })
const exp = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//date/holidays//NONSGML v1.0//EN
METHOD:PUBLISH
BEGIN:VEVENT
CREATED:20160130T120534Z
LAST-MODIFIED:20160130T120534Z
DTSTAMP:20160130T120534Z
SUMMARY:Neujahr
DTSTART;VALUE=DATE:20160101
DTEND;VALUE=DATE:20160102
DESCRIPTION:public
TRANSP:TRANSPARENT
UID:713946806965395@date-holidays
END:VEVENT
END:VCALENDAR
`
assert.strictEqual(comp(res), comp(exp))
})

it('can generate a calendar with one fullday entry and time shown as free', function () {
const res = vcalendar([].concat(dates[dates.length - 1]), { fullday: 1 })
const exp = `BEGIN:VCALENDAR
Expand Down

0 comments on commit c9bd93b

Please sign in to comment.