updated calendar to have today, tomorrow and this week
This commit is contained in:
parent
9c4ef95858
commit
2de941d389
@ -1,12 +1,31 @@
|
||||
var swedishword = require('./today/swedishword');
|
||||
var log4js = require('log4js');
|
||||
var logger = log4js.getLogger();
|
||||
|
||||
var calHandler = require('./today/calHandler');
|
||||
|
||||
|
||||
require('sugar-date');
|
||||
|
||||
var cal = {today: [], tomorrow: [], week: []};
|
||||
var _cal_tmp = {today: [], tomorrow: [], week: []};
|
||||
|
||||
for (var t = 0; t < calHandler.calendars.length;t++) {
|
||||
calHandler.getAdvancedCalV3(calHandler.calendars[t])
|
||||
.then((d) => {
|
||||
'use strict';
|
||||
cal.today = cal.today.concat(d.today);
|
||||
cal.tomorrow = cal.tomorrow.concat(d.tomorrow);
|
||||
cal.week = cal.week.concat(d.week);
|
||||
|
||||
|
||||
logger.error(cal);
|
||||
})
|
||||
.catch((e) => {
|
||||
'use strict';
|
||||
logger.error(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
swedishword.getSwedishWord()
|
||||
.then((d) => {
|
||||
"use strict";
|
||||
console.log('Wanted result: ' , d);
|
||||
})
|
||||
.catch((e)=>{
|
||||
"use strict";
|
||||
console.error(e);
|
||||
});
|
||||
|
@ -13,17 +13,120 @@ function processICAL(ical) {
|
||||
var segments = {
|
||||
meetingStartID: 'DTSTART;TZID=Europe/London:',
|
||||
meetingStartAlt: 'DTSTART:',
|
||||
meetingStartAltOther: 'DTSTART;VALUE=DATE:',
|
||||
meetingEndID: 'DTEND;TZID=Europe/London:',
|
||||
meetingEndAlt: 'DTEND:',
|
||||
meetingEndAltOther: 'DTEND;VALUE=DATE:',
|
||||
meetingDescID: 'DESCRIPTION:',
|
||||
summaryID: 'SUMMARY:',
|
||||
begin: 'BEGIN:VEVENT',
|
||||
end: 'END:VEVENT',
|
||||
beginAlarm: 'BEGIN:VALARM',
|
||||
recur: 'RRULE'
|
||||
endAlarm: 'END:VALARM',
|
||||
recur: 'RRULE:'
|
||||
};
|
||||
|
||||
var rules = ['FREQ','WKST','UNTIL','BYMONTH','BYMONTHDAY','INTERVAL','BYDAY'];
|
||||
|
||||
function nThDayOfMonth(monthsAhead, wantedDay) {
|
||||
var now = new Date();
|
||||
|
||||
for(var t=0; t < monthsAhead; t++) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function processRecurrence(workBlock) {
|
||||
var _workBlock = workBlock;
|
||||
// logger.debug('Processing recurrence...');
|
||||
// logger.debug('Processing recurrence...');
|
||||
var blocks=[];
|
||||
var now = new Date();
|
||||
var day = now.getDate();
|
||||
var month = now.getMonth();
|
||||
var year = now.getFullYear();
|
||||
|
||||
var recurSettings = {freq:null, wkst:null, until:null, bymonth:null, bymonthday:null, interval:null, byday:null};
|
||||
|
||||
var firstSplit = _workBlock.recur.split(';');
|
||||
|
||||
for (var t=0; t< firstSplit.length;t++)
|
||||
{
|
||||
var ws = firstSplit[t].split('=');
|
||||
if (rules.indexOf(ws[0]) > -1) {
|
||||
recurSettings[ws[0].toLowerCase()] = ws[1];
|
||||
}
|
||||
}
|
||||
|
||||
// if all null discard..
|
||||
|
||||
if (recurSettings.freq === null && recurSettings.wkst === null && recurSettings.until === null && recurSettings.byday === null && recurSettings.bymonth === null && recurSettings.bymonthday === null && recurSettings.interval === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (recurSettings.until !== null) {
|
||||
// have we expired?
|
||||
//var _until = Date.create(recurSettings.until).isPast();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (recurSettings.freq !== null) {
|
||||
|
||||
// logger.debug(_workBlock);
|
||||
var origStart, origEnd, distance, newStart, newEnd;
|
||||
|
||||
origStart = Date.create(_workBlock.dtstart);
|
||||
origEnd = Date.create(_workBlock.dtend);
|
||||
var _d = origStart.getDate();
|
||||
var _m = origStart.getMonth();
|
||||
var _h = origStart.getHours();
|
||||
var _min = origStart.getMinutes();
|
||||
var _secs = origStart.getSeconds();
|
||||
distance = origEnd - origStart;
|
||||
|
||||
|
||||
if (recurSettings.freq === 'YEARLY') {
|
||||
|
||||
if (recurSettings.bymonth !== null && recurSettings.bymonthday !== null) {
|
||||
// ok, a day and month.
|
||||
newStart = Date.create().set({year:year, month: recurSettings.bymonth - 1 , day: recurSettings.bymonthday, hour:_h, minutes:_min, seconds:_secs});
|
||||
newEnd = Date.create(newStart).addMilliseconds(distance);
|
||||
_workBlock.dtstart = newStart;
|
||||
_workBlock.dtend = newEnd;
|
||||
|
||||
} else if (recurSettings.bymonth === null && recurSettings.bymonthday === null) {
|
||||
// extract month and year from dtstart
|
||||
newStart = Date.create().set({year:year, month: _m , day: _d, hour:_h, minutes:_min, seconds:_secs});
|
||||
newEnd = Date.create(newStart).addMilliseconds(distance);
|
||||
_workBlock.dtstart = newStart;
|
||||
_workBlock.dtend = newEnd;
|
||||
|
||||
}
|
||||
|
||||
return _workBlock;
|
||||
}
|
||||
|
||||
if (recurSettings.freq === 'MONTHLY') {
|
||||
if (recurSettings.bymonthday !== null) {
|
||||
// ok, a day and month.
|
||||
newStart = Date.create().set({year:year, month: month , day: recurSettings.bymonthday, hour:_h, minutes:_min, seconds:_secs});
|
||||
newEnd = Date.create(newStart).addMilliseconds(distance);
|
||||
|
||||
_workBlock.dtstart = newStart;
|
||||
_workBlock.dtend = newEnd;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we get here we've skipped everything just return the _workblock
|
||||
|
||||
return _workBlock;
|
||||
}
|
||||
|
||||
function processBlock(block) {
|
||||
var _wb;
|
||||
var workBlock = {
|
||||
summary: '',
|
||||
dtstart: null,
|
||||
@ -32,11 +135,16 @@ function processICAL(ical) {
|
||||
timeStart: null,
|
||||
timeEnd: null,
|
||||
duration: 0,
|
||||
combined: ''
|
||||
combined: '',
|
||||
recur: null
|
||||
};
|
||||
var alarmFlag = false, ws, blockStep;
|
||||
for (var step = 0; step < block.length; step++) {
|
||||
blockStep = block[step];
|
||||
if (blockStep.indexOf(segments.recur) >= 0) {
|
||||
workBlock.recur = STRING(block[step].split(segments.recur)[1]).collapseWhitespace().s;
|
||||
}
|
||||
|
||||
if (blockStep.indexOf(segments.summaryID) >= 0) {
|
||||
workBlock.summary = STRING(block[step].split(segments.summaryID)[1]).collapseWhitespace().s;
|
||||
}
|
||||
@ -56,6 +164,17 @@ function processICAL(ical) {
|
||||
ws = STRING(block[step].split(segments.meetingEndAlt)[1]).collapseWhitespace().s;
|
||||
workBlock.dtend = Date.create(ws);
|
||||
}
|
||||
|
||||
if (blockStep.indexOf(segments.meetingStartAltOther) >= 0) {
|
||||
ws = STRING(block[step].split(segments.meetingStartAltOther)[1]).collapseWhitespace().s;
|
||||
workBlock.dtstart = Date.create(ws);
|
||||
}
|
||||
if (blockStep.indexOf(segments.meetingEndAltOther) >= 0) {
|
||||
ws = STRING(block[step].split(segments.meetingEndAltOther)[1]).collapseWhitespace().s;
|
||||
workBlock.dtend = Date.create(ws);
|
||||
}
|
||||
|
||||
|
||||
if (blockStep.indexOf(segments.meetingDescID) >= 0) {
|
||||
if (!alarmFlag) {
|
||||
workBlock.description = STRING(block[step].split(segments.meetingDescID)[1]).collapseWhitespace().s;
|
||||
@ -66,6 +185,23 @@ function processICAL(ical) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We have to check recuring stuff before the cron stuff is processed.
|
||||
|
||||
if (workBlock.recur !== null) {
|
||||
|
||||
_wb = processRecurrence(workBlock);
|
||||
// logger.warn('returning:', _wb);
|
||||
if (_wb !== null) {
|
||||
if (!Array.isArray(_wb)) {
|
||||
workBlock = _wb;
|
||||
} else {
|
||||
logger.error('We made an array');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//logger.debug(workBlock);
|
||||
if (workBlock.dtstart !== null) {
|
||||
workBlock.timeStart = workBlock.dtstart.format('{24hr}:{mm}:{ss}');
|
||||
workBlock.combined = '<em>' + workBlock.timeStart + '</em> - ';
|
||||
@ -88,14 +224,26 @@ function processICAL(ical) {
|
||||
|
||||
var lines = ical.split('\r\n'), l = lines.length, counter = 0;
|
||||
|
||||
var alarmed = false;
|
||||
while (counter < l) {
|
||||
if (lines[counter].indexOf(segments.begin) < 0) {
|
||||
counter++;
|
||||
} else {
|
||||
var subcounter = 0, subBlock = [];
|
||||
alarmed = false;
|
||||
while (subcounter < 75) {
|
||||
if (lines[counter + subcounter].indexOf(segments.end) < 0) {
|
||||
subBlock.push(lines[counter + subcounter]);
|
||||
|
||||
if (lines[counter + subcounter].indexOf(segments.beginAlarm) > -1) {
|
||||
alarmed = true;
|
||||
}
|
||||
if (!alarmed) {
|
||||
subBlock.push(lines[counter + subcounter]);
|
||||
}
|
||||
if (lines[counter + subcounter].indexOf(segments.endAlarm) > -1) {
|
||||
alarmed = false;
|
||||
}
|
||||
|
||||
subcounter++;
|
||||
} else {
|
||||
break;
|
||||
@ -103,8 +251,13 @@ function processICAL(ical) {
|
||||
}
|
||||
counter = counter + subcounter;
|
||||
var b = processBlock(subBlock);
|
||||
if (b.dtstart !== null) {
|
||||
workingBlock.push(b);
|
||||
if (Array.isArray(b)) {
|
||||
logger.error('!returned an array...');
|
||||
} else {
|
||||
if (b.dtstart !== null) {
|
||||
workingBlock.push(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -163,12 +316,12 @@ module.exports = {
|
||||
var now, twoDays, sevenDays;
|
||||
|
||||
now = Date.create('today');
|
||||
logger.debug(now);
|
||||
// logger.debug(now);
|
||||
twoDays = Date.create(now).addDays(2).beginningOfDay();
|
||||
logger.debug(twoDays);
|
||||
// logger.debug(twoDays);
|
||||
sevenDays = Date.create(twoDays).addDays(5).beginningOfDay();
|
||||
|
||||
logger.debug(now, twoDays, sevenDays);
|
||||
// logger.debug(now, twoDays, sevenDays);
|
||||
|
||||
for (var t = 0; t < this.jsonBlock.length; t++) {
|
||||
if (this.jsonBlock[t].dtstart.isBetween(twoDays, sevenDays)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user