fix: Issue #1798 - fixing recurrent calendar events crosstime DST

This commit is contained in:
Kurtis Blankenship
2020-01-17 22:53:14 -06:00
parent 5bf90ae31d
commit 8aa745471b
10 changed files with 235 additions and 228 deletions

View File

@@ -184,7 +184,14 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
// For recurring events, get the set of start dates that fall within the range
// of dates we"re looking for.
var dates = rule.between(past, future, true, limitFunction);
// kblankenship1989 - to fix issue #1798, converting all dates to locale time first, then converting back to UTC time
var pastLocal = moment(past).subtract(past.getTimezoneOffset(), "minutes").toDate();
var futureLocal = moment(past).subtract(future.getTimezoneOffset(), "minutes").toDate();
var datesLocal = rule.between(pastLocal, futureLocal, true, limitFunction);
var dates = datesLocal.map(function(dateLocal) {
var date = moment(dateLocal).add(dateLocal.getTimezoneOffset(), "minutes").toDate();
return date;
});
// The "dates" array contains the set of dates within our desired date range range that are valid
// for the recurrence rule. *However*, it"s possible for us to have a specific recurrence that

View File

@@ -26,6 +26,17 @@ exports.parseFile = function(filename){
var rrule = require('rrule').RRule
function getLocaleISOString(date) {
var year = date.getFullYear().toString(10).padStart(4,'0');
var month = date.getMonth().toString(10).padStart(2,'0');
var day = date.getDate().toString(10).padStart(2,'0');
var hour = date.getHours().toString(10).padStart(2,'0');
var minute = date.getMinutes().toString(10).padStart(2,'0');
var second = date.getSeconds().toString(10).padStart(2,'0');
return `${year}${month}${day}T${hour}${minute}${second}Z`;
}
ical.objectHandlers['RRULE'] = function(val, params, curr, stack, line){
curr.rrule = line;
return curr
@@ -50,8 +61,8 @@ ical.objectHandlers['END'] = function (val, params, curr, stack) {
if (typeof curr.start.toISOString === 'function') {
try {
rule += ';DTSTART=' + curr.start.toISOString().replace(/[-:]/g, '');
rule = rule.replace(/\.[0-9]{3}/, '');
// kblankenship1989 - to fix issue #1798, converting all dates to locale time first, then converting back to UTC time
rule += ';DTSTART=' + getLocaleISOString(curr.start);
} catch (error) {
console.error("ERROR when trying to convert to ISOString", error);
}

View File

@@ -39,7 +39,7 @@ Module.register("compliments", {
afternoonEndTime: 17,
random: true
},
lastIndexUsed:-1,
lastIndexUsed:-1,
// Set currentweather from module
currentWeatherType: "",
@@ -151,7 +151,7 @@ Module.register("compliments", {
// get the current time of day compliments list
var compliments = this.complimentArray();
// variable for index to next message to display
let index=0
let index=0;
// are we randomizing
if(this.config.random){
// yes
@@ -160,28 +160,28 @@ Module.register("compliments", {
else{
// no, sequetial
// if doing sequential, don't fall off the end
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed;
}
return compliments[index];
},
// Override dom generator.
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
// get the compliment text
// get the compliment text
var complimentText = this.randomCompliment();
// split it into parts on newline text
var parts= complimentText.split('\n')
// split it into parts on newline text
var parts= complimentText.split("\n");
// create a span to hold it all
var compliment=document.createElement('span')
// process all the parts of the compliment text
var compliment=document.createElement("span");
// process all the parts of the compliment text
for (part of parts){
// create a text element for each part
compliment.appendChild(document.createTextNode(part))
compliment.appendChild(document.createTextNode(part));
// add a break `
compliment.appendChild(document.createElement('BR'))
compliment.appendChild(document.createElement("BR"));
}
// remove the last break
compliment.lastElementChild.remove();