Skip to content

Commit

Permalink
mivExchangeCalendar.js: getItemsFromMemoryCache: fix looking for item…
Browse files Browse the repository at this point in the history
…s in cache

The code before were using simple day index to go through start and end of the
range. Furthermore, it didn't managed that range were given in local timezone
and memory cache is in UTC.

This fix use Lightning tools to go through range and it converts local timezone
to UTC, so the cache is correctly read.

Fixes Ericsson#67
  • Loading branch information
Trim committed Aug 25, 2017
1 parent deeea44 commit 8963df8
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions interfaces/exchangeCalendar/mivExchangeCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2842,30 +2842,31 @@ calExchangeCalendar.prototype = {

// This is by using the this.itemCacheByStartDate and this.itemCacheByEndDate index.
if (wantEvents) {

var startYear = aRangeStart.year;
var startYearday = aRangeStart.yearday;

var endYear = aRangeEnd.year;
var endYearday = aRangeEnd.yearday;
var doStop = false;
var ids = {};
while (!doStop) {
if ((startYear == endYear) && (startYearday == endYearday)) {
doStop = true;
}

if ((this.itemCacheByStartDate) && (this.itemCacheByStartDate[startYear]) && (this.itemCacheByStartDate[startYear][startYearday])) {
for (var itemid in this.itemCacheByStartDate[startYear][startYearday]) {
let ids = {};

let dayOffset = cal.createDuration();
dayOffset.days = 1;

let dayPos = cal.createDateTime();
dayPos = aRangeStart.clone();

// Convert date from local timezone to UTC
// Given range is in local timezone and cache save in UTC
dayPos.isDate = false;
dayPos = dayPos.getInTimezone(cal.UTC());
dayPos.isDate = true;

// Go through all days bewteen the range start day and the range end day
while (dayPos.compare(aRangeEnd) < 0 ) {
if (this.itemCacheByStartDate
&& this.itemCacheByStartDate[dayPos.year]
&& this.itemCacheByStartDate[dayPos.year][dayPos.yearday]) {
for (let itemid in this.itemCacheByStartDate[dayPos.year][dayPos.yearday]) {
ids[itemid] = true;
}
}

startYearday++;
if (startYearday > 366) {
startYear++;
startYearday = 1;
}
dayPos.addDuration(dayOffset);
}

// For all found ids, if item cache has it, push it to events answer
Expand Down

0 comments on commit 8963df8

Please sign in to comment.