Skip to content
Permalink
Browse files

Ensure that START < DUE if both set

  • Loading branch information...
korelstar committed Nov 22, 2016
1 parent 1743316 commit 24b381d46a8e7fb1cf993f5ea8be618760b0f402
Showing with 74 additions and 8 deletions.
  1. +37 −4 js/app/services/businesslayer/tasksbusinesslayer.js
  2. +37 −4 js/public/app.js
@@ -149,9 +149,16 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
};

TasksBusinessLayer.prototype.initDueDate = function(task) {
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
if (!due.isValid()) {
return this.setDue(task, moment().startOf('hour').add(1, 'h'), 'time');
var reference = start.isAfter() ? start : moment();
if(task.allDay) {
reference.startOf('day').add(1, 'd');
} else {
reference.startOf('hour').add(1, 'h');
}
return this.setDue(task, reference, 'all');
}
};

@@ -160,7 +167,9 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
type = 'day';
}
var allDay = task.allDay;
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var olddue = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var due = olddue.clone();
if (type === 'day') {
if (moment(due).isValid()) {
due.year(date.year()).month(date.month()).date(date.date());
@@ -178,6 +187,10 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
} else {
return;
}
if(due.isBefore(start) || due.isSame(start)) {
start.subtract(olddue.diff(due), 'ms');
task.start = this.momentToICALTime(start, allDay);
}
task.due = this.momentToICALTime(due, allDay);
// this.checkReminderDate(task);
this.doUpdate(task);
@@ -194,8 +207,12 @@ angular.module('Tasks').factory('TasksBusinessLayer', [

TasksBusinessLayer.prototype.initStartDate = function(task) {
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
if (!start.isValid()) {
return this.setStart(task, moment().startOf('hour').add(1, 'h'), 'time');
var reference = due.isBefore() ? due : moment();
reference.subtract(1, 'm');
reference.startOf(task.allDay ? 'day' : 'hour');
return this.setStart(task, reference, 'all');
}
};

@@ -204,7 +221,9 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
type = 'day';
}
var allDay = task.allDay;
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var oldstart = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var start = oldstart.clone();
if (type === 'day') {
if (moment(start).isValid()) {
start.year(date.year()).month(date.month()).date(date.date());
@@ -217,9 +236,15 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
} else {
start = date;
}
} else if (type === 'all') {
start = date;
} else {
return;
}
if(start.isAfter(due) || start.isSame(due)) {
due.add(start.diff(oldstart), 'ms');
task.due = this.momentToICALTime(due, allDay);
}
task.start = this.momentToICALTime(start, allDay);
// this.checkReminderDate(taskID);
this.doUpdate(task);
@@ -236,6 +261,14 @@ angular.module('Tasks').factory('TasksBusinessLayer', [

TasksBusinessLayer.prototype.setAllDay = function(task, allDay) {
task.allDay = allDay;
if(allDay) {
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
if(start.isAfter(due) || start.isSame(due)) {
start = moment(due).subtract(1, 'day');
task.start = this.momentToICALTime(start, allDay);
}
}
this.doUpdate(task);
};

@@ -2178,9 +2178,16 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
};

TasksBusinessLayer.prototype.initDueDate = function(task) {
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
if (!due.isValid()) {
return this.setDue(task, moment().startOf('hour').add(1, 'h'), 'time');
var reference = start.isAfter() ? start : moment();
if(task.allDay) {
reference.startOf('day').add(1, 'd');
} else {
reference.startOf('hour').add(1, 'h');
}
return this.setDue(task, reference, 'all');
}
};

@@ -2189,7 +2196,9 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
type = 'day';
}
var allDay = task.allDay;
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var olddue = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var due = olddue.clone();
if (type === 'day') {
if (moment(due).isValid()) {
due.year(date.year()).month(date.month()).date(date.date());
@@ -2207,6 +2216,10 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
} else {
return;
}
if(due.isBefore(start) || due.isSame(start)) {
start.subtract(olddue.diff(due), 'ms');
task.start = this.momentToICALTime(start, allDay);
}
task.due = this.momentToICALTime(due, allDay);
// this.checkReminderDate(task);
this.doUpdate(task);
@@ -2223,8 +2236,12 @@ angular.module('Tasks').factory('TasksBusinessLayer', [

TasksBusinessLayer.prototype.initStartDate = function(task) {
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
if (!start.isValid()) {
return this.setStart(task, moment().startOf('hour').add(1, 'h'), 'time');
var reference = due.isBefore() ? due : moment();
reference.subtract(1, 'm');
reference.startOf(task.allDay ? 'day' : 'hour');
return this.setStart(task, reference, 'all');
}
};

@@ -2233,7 +2250,9 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
type = 'day';
}
var allDay = task.allDay;
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var oldstart = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
var start = oldstart.clone();
if (type === 'day') {
if (moment(start).isValid()) {
start.year(date.year()).month(date.month()).date(date.date());
@@ -2246,9 +2265,15 @@ angular.module('Tasks').factory('TasksBusinessLayer', [
} else {
start = date;
}
} else if (type === 'all') {
start = date;
} else {
return;
}
if(start.isAfter(due) || start.isSame(due)) {
due.add(start.diff(oldstart), 'ms');
task.due = this.momentToICALTime(due, allDay);
}
task.start = this.momentToICALTime(start, allDay);
// this.checkReminderDate(taskID);
this.doUpdate(task);
@@ -2265,6 +2290,14 @@ angular.module('Tasks').factory('TasksBusinessLayer', [

TasksBusinessLayer.prototype.setAllDay = function(task, allDay) {
task.allDay = allDay;
if(allDay) {
var due = moment(task.due, "YYYY-MM-DDTHH:mm:ss");
var start = moment(task.start, "YYYY-MM-DDTHH:mm:ss");
if(start.isAfter(due) || start.isSame(due)) {
start = moment(due).subtract(1, 'day');
task.start = this.momentToICALTime(start, allDay);
}
}
this.doUpdate(task);
};

0 comments on commit 24b381d

Please sign in to comment.
You can’t perform that action at this time.