Skip to content

Commit

Permalink
fix: issue #76, trigger cronjob event in past
Browse files Browse the repository at this point in the history
  • Loading branch information
naimo84 committed Jan 14, 2021
1 parent a7ba7b5 commit bd381cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/ical-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}).attr('selected', true);
}

if (!this.offsettUnits) {
if (!this.offsetUnits) {
$("#node-input-offsetUnits option").filter(function () {
return $(this).val() == 'minutes';
}).attr('selected', true);
Expand Down
43 changes: 17 additions & 26 deletions src/ical-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@ module.exports = function (RED: Red) {
if (output) {
const eventStart = new Date(ev.start);
const eventEnd = new Date(ev.end);

if (node.config.offset) {
if (node.config?.offsetUnits === 'seconds') {
eventStart.setSeconds(eventStart.getSeconds() + node.config.offset);
eventEnd.setSeconds(eventEnd.getSeconds() + node.config.offset);
} else if (node.config?.offsetUnits === 'hours') {
eventStart.setHours(eventStart.getHours() + node.config.offset);
eventEnd.setHours(eventEnd.getHours() + node.config.offset);
} else if (node.config?.offsetUnits === 'days') {
eventStart.setDate(eventStart.getDate() + node.config.offset);
eventEnd.setDate(eventEnd.getDate() + node.config.offset);
} else {
eventStart.setMinutes(eventStart.getMinutes() + node.config.offset);
eventEnd.setMinutes(eventEnd.getMinutes() + node.config.offset);
}
}

if (eventStart > dateNow) {
let uid = crypto.MD5(ev.created + ev.summary + "start").toString();
if (ev.uid) {
Expand All @@ -283,20 +300,6 @@ module.exports = function (RED: Red) {
countdown: countdown(new Date(ev.start))
}


if (node.config.offset) {
if (node.config?.offsetUnits === 'seconds') {
eventStart.setSeconds(eventStart.getSeconds() + node.config.offset);
} else if (node.config?.offsetUnits === 'hours') {
eventStart.setMinutes(eventStart.getMinutes() + node.config.offset);
} else if (node.config?.offsetUnits === 'days') {
eventStart.setDate(eventStart.getDate() + node.config.offset);
} else {
eventStart.setMinutes(eventStart.getMinutes() + node.config.offset);
}
}


let job2 = new CronJob(eventStart, cronJobStart.bind(null, event, node));
let cronJob = startedCronJobs[uid];
if (!newCronJobs.has(uid) && !cronJob) {
Expand Down Expand Up @@ -329,18 +332,6 @@ module.exports = function (RED: Red) {
countdown: countdown(new Date(ev.start))
}

if (node.config.offset) {
if (node.config?.offsetUnits === 'seconds') {
eventEnd.setSeconds(eventEnd.getSeconds() + node.config.offset);
} else if (node.config?.offsetUnits === 'hours') {
eventEnd.setMinutes(eventEnd.getMinutes() + node.config.offset);
} else if (node.config?.offsetUnits === 'days') {
eventEnd.setDate(eventEnd.getDate() + node.config.offset);
} else {
eventEnd.setMinutes(eventEnd.getMinutes() + node.config.offset);
}
}

let job2 = new CronJob(eventEnd, cronJobEnd.bind(null, event, node));
let cronJob = startedCronJobs[uid];
if (!newCronJobs.has(uid) && !startedCronJobs[uid]) {
Expand Down

0 comments on commit bd381cf

Please sign in to comment.