|
|
@ -53,6 +53,7 @@ exports.updateHiddenDates = function (body, hiddenDates) { |
|
|
|
var duration = endDate - startDate; |
|
|
|
if (duration >= 4 * pixelTime) { |
|
|
|
var offset = 0; |
|
|
|
var runUntil = end.clone(); |
|
|
|
switch (hiddenDates[i].repeat) { |
|
|
|
case "daily": // case of time
|
|
|
|
if (startDate.day() != endDate.day()) { |
|
|
@ -64,44 +65,62 @@ exports.updateHiddenDates = function (body, hiddenDates) { |
|
|
|
|
|
|
|
endDate.dayOfYear(start.dayOfYear()); |
|
|
|
endDate.year(start.year()); |
|
|
|
endDate.subtract(7,'days'); |
|
|
|
endDate.add(offset,'days'); |
|
|
|
endDate.subtract(7 - offset,'days'); |
|
|
|
|
|
|
|
runUntil.add(1, 'weeks'); |
|
|
|
break; |
|
|
|
case "weekly": |
|
|
|
if (startDate.week() != endDate.week()) { |
|
|
|
offset = 1; |
|
|
|
} |
|
|
|
startDate.week(start.week() - 1); |
|
|
|
var dayOffset = endDate.diff(startDate,'days') |
|
|
|
var day = startDate.day(); |
|
|
|
|
|
|
|
// set the start date to the range.start
|
|
|
|
startDate.date(start.date()); |
|
|
|
startDate.month(start.month()); |
|
|
|
startDate.year(start.year()); |
|
|
|
endDate = startDate.clone(); |
|
|
|
|
|
|
|
endDate.week(start.week() - 1); |
|
|
|
endDate.year(start.year()); |
|
|
|
endDate.add(offset,'weeks'); |
|
|
|
// force
|
|
|
|
startDate.day(day); |
|
|
|
endDate.day(day); |
|
|
|
endDate.add(dayOffset,'days'); |
|
|
|
|
|
|
|
startDate.subtract(1,'weeks'); |
|
|
|
endDate.subtract(1,'weeks'); |
|
|
|
|
|
|
|
runUntil.add(1, 'weeks'); |
|
|
|
break |
|
|
|
case "monthly": |
|
|
|
if (startDate.month() != endDate.month()) { |
|
|
|
offset = 1; |
|
|
|
} |
|
|
|
startDate.month(start.month() - 1) |
|
|
|
startDate.month(start.month()); |
|
|
|
startDate.year(start.year()); |
|
|
|
startDate.subtract(1,'months'); |
|
|
|
|
|
|
|
endDate.month(start.month() - 1); |
|
|
|
endDate.month(start.month()); |
|
|
|
endDate.year(start.year()); |
|
|
|
endDate.subtract(1,'months'); |
|
|
|
endDate.add(offset,'months'); |
|
|
|
|
|
|
|
runUntil.add(1, 'months'); |
|
|
|
break; |
|
|
|
case "yearly": |
|
|
|
if (startDate.year() != endDate.year()) { |
|
|
|
offset = 1; |
|
|
|
} |
|
|
|
startDate.year(start.year() - 1); |
|
|
|
endDate.year(start.year() - 1); |
|
|
|
startDate.year(start.year()); |
|
|
|
startDate.subtract(1,'years'); |
|
|
|
endDate.year(start.year()); |
|
|
|
endDate.subtract(1,'years'); |
|
|
|
endDate.add(offset,'years'); |
|
|
|
|
|
|
|
runUntil.add(1, 'years'); |
|
|
|
break; |
|
|
|
default: |
|
|
|
console.log("Wrong repeat format, allowed are: daily, weekly, monthly, yearly. Given:", hiddenDates[i].repeat); |
|
|
|
return; |
|
|
|
} |
|
|
|
while (startDate < end) { |
|
|
|
while (startDate < runUntil) { |
|
|
|
body.hiddenDates.push({start: startDate.valueOf(), end: endDate.valueOf()}); |
|
|
|
switch (hiddenDates[i].repeat) { |
|
|
|
case "daily": |
|
|
@ -109,8 +128,8 @@ exports.updateHiddenDates = function (body, hiddenDates) { |
|
|
|
endDate.add(1, 'days'); |
|
|
|
break; |
|
|
|
case "weekly": |
|
|
|
startDate.add(7, 'days'); |
|
|
|
endDate.add(7, 'days'); |
|
|
|
startDate.add(1, 'weeks'); |
|
|
|
endDate.add(1, 'weeks'); |
|
|
|
break |
|
|
|
case "monthly": |
|
|
|
startDate.add(1, 'months'); |
|
|
@ -129,10 +148,9 @@ exports.updateHiddenDates = function (body, hiddenDates) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// remove duplicates, merge where possible
|
|
|
|
exports.removeDuplicates(body); |
|
|
|
|
|
|
|
//exports.printDates(body.hiddenDates)
|
|
|
|
// ensure the new positions are not on hidden dates
|
|
|
|
var startHidden = exports.isHidden(body.range.start, body.hiddenDates); |
|
|
|
var endHidden = exports.isHidden(body.range.end,body.hiddenDates); |
|
|
@ -144,6 +162,7 @@ exports.updateHiddenDates = function (body, hiddenDates) { |
|
|
|
body.range._applyRange(rangeStart, rangeEnd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -260,7 +279,7 @@ exports.toScreen = function(Core, time, width) { |
|
|
|
time = hidden.startDate; |
|
|
|
} |
|
|
|
|
|
|
|
var duration = exports.getHiddenDuration(Core.body.hiddenDates, Core.range); |
|
|
|
var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end); |
|
|
|
time = exports.correctTimeForHidden(Core.body.hiddenDates, Core.range, time); |
|
|
|
|
|
|
|
var conversion = Core.range.conversion(width, duration); |
|
|
@ -277,7 +296,7 @@ exports.toScreen = function(Core, time, width) { |
|
|
|
* @returns {Date} |
|
|
|
*/ |
|
|
|
exports.toTime = function(body, range, x, width) { |
|
|
|
var hiddenDuration = exports.getHiddenDuration(body.hiddenDates, range); |
|
|
|
var hiddenDuration = exports.getHiddenDurationBetween(body.hiddenDates, range.start, range.end); |
|
|
|
var totalDuration = range.end - range.start - hiddenDuration; |
|
|
|
var partialDuration = totalDuration * x / width; |
|
|
|
var accumulatedHiddenDuration = exports.getAccumulatedHiddenDuration(body.hiddenDates,range, partialDuration); |
|
|
@ -290,17 +309,17 @@ exports.toTime = function(body, range, x, width) { |
|
|
|
/** |
|
|
|
* Support function |
|
|
|
* |
|
|
|
* @param hiddenTimes |
|
|
|
* @param hiddenDates |
|
|
|
* @param range |
|
|
|
* @returns {number} |
|
|
|
*/ |
|
|
|
exports.getHiddenDuration = function(hiddenTimes, range) { |
|
|
|
exports.getHiddenDurationBetween = function(hiddenDates, start, end) { |
|
|
|
var duration = 0; |
|
|
|
for (var i = 0; i < hiddenTimes.length; i++) { |
|
|
|
var startDate = hiddenTimes[i].start; |
|
|
|
var endDate = hiddenTimes[i].end; |
|
|
|
for (var i = 0; i < hiddenDates.length; i++) { |
|
|
|
var startDate = hiddenDates[i].start; |
|
|
|
var endDate = hiddenDates[i].end; |
|
|
|
// if time after the cutout, and the
|
|
|
|
if (startDate >= range.start && endDate < range.end) { |
|
|
|
if (startDate >= start && endDate < end) { |
|
|
|
duration += endDate - startDate; |
|
|
|
} |
|
|
|
} |
|
|
@ -374,14 +393,14 @@ exports.getAccumulatedHiddenDuration = function(hiddenDates, range, requiredDura |
|
|
|
|
|
|
|
/** |
|
|
|
* used to step over to either side of a hidden block. Correction is disabled on tablets, might be set to true |
|
|
|
* @param hiddenTimes |
|
|
|
* @param hiddenDates |
|
|
|
* @param time |
|
|
|
* @param direction |
|
|
|
* @param correctionEnabled |
|
|
|
* @returns {*} |
|
|
|
*/ |
|
|
|
exports.snapAwayFromHidden = function(hiddenTimes, time, direction, correctionEnabled) { |
|
|
|
var isHidden = exports.isHidden(time, hiddenTimes); |
|
|
|
exports.snapAwayFromHidden = function(hiddenDates, time, direction, correctionEnabled) { |
|
|
|
var isHidden = exports.isHidden(time, hiddenDates); |
|
|
|
if (isHidden.hidden == true) { |
|
|
|
if (direction < 0) { |
|
|
|
if (correctionEnabled == true) { |
|
|
@ -411,19 +430,18 @@ exports.snapAwayFromHidden = function(hiddenTimes, time, direction, correctionEn |
|
|
|
* Check if a time is hidden |
|
|
|
* |
|
|
|
* @param time |
|
|
|
* @param hiddenTimes |
|
|
|
* @param hiddenDates |
|
|
|
* @returns {{hidden: boolean, startDate: Window.start, endDate: *}} |
|
|
|
*/ |
|
|
|
exports.isHidden = function(time, hiddenTimes) { |
|
|
|
var isHidden = false; |
|
|
|
for (var i = 0; i < hiddenTimes.length; i++) { |
|
|
|
var startDate = hiddenTimes[i].start; |
|
|
|
var endDate = hiddenTimes[i].end; |
|
|
|
exports.isHidden = function(time, hiddenDates) { |
|
|
|
for (var i = 0; i < hiddenDates.length; i++) { |
|
|
|
var startDate = hiddenDates[i].start; |
|
|
|
var endDate = hiddenDates[i].end; |
|
|
|
|
|
|
|
if (time >= startDate && time < endDate) { // if the start is entering a hidden zone
|
|
|
|
isHidden = true; |
|
|
|
return {hidden: true, startDate: startDate, endDate: endDate}; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return {hidden: isHidden, startDate: startDate, endDate: endDate}; |
|
|
|
return {hidden: false, startDate: startDate, endDate: endDate}; |
|
|
|
} |