From ac805bba6be003da653a2a7fec7cb1f4aa351ecd Mon Sep 17 00:00:00 2001 From: Diluka W Date: Wed, 29 Dec 2021 17:56:39 +0800 Subject: [PATCH] fix: holiday range --- .gitignore | 2 ++ index.js | 9 ++++++--- package.json | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 780d713..e500077 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,5 @@ dist # OS .DS_Store + +calendar.ics diff --git a/index.js b/index.js index 26c8965..942e4e1 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,13 @@ async function createCalendar() { for (const event of book.events()) { console.log(event.name, event.days(), event.isHoliday(), event.isWorkingday()); + const from = _.first(event.days()); + const to = _.last(event.days()); + calendar.createEvent({ - id: `HD-CN-${+_.first(event.days())}`, - start: moment(_.first(event.days())).startOf('d'), - end: moment(_.last(event.days())).endOf('d'), + id: `HD-CN-${+from}`, + start: moment(from), + end: moment(to).add(1, 'd'), summary: event.name + (event.isWorkingday() ? '补班' : ''), allDay: true, alarms: event.isWorkingday() diff --git a/package.json b/package.json index 0882cba..54d9ed3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "main": "index.js", "type": "module", "scripts": { - "start": "node ." + "start": "node .", + "test:download": "curl -sSL localhost:3000 -o calendar.ics" }, "keywords": [], "author": "Diluka", @@ -26,4 +27,4 @@ "eslint-plugin-prettier": "^4.0.0", "prettier": "^2.5.1" } -} +} \ No newline at end of file