Unverified Commit 9b36258d authored by ransome's avatar ransome Committed by GitHub
Browse files

Merge pull request #137 from zerodat/recur_period_fix

fix month, year recurrence periods to be more accurate
parents c254396c 057fc29d
...@@ -58,6 +58,7 @@ function generateRecurrence(todo) { ...@@ -58,6 +58,7 @@ function generateRecurrence(todo) {
function getRecurrenceDate(due, recurrence) { function getRecurrenceDate(due, recurrence) {
let recSplit = splitRecurrence(recurrence); let recSplit = splitRecurrence(recurrence);
let days = 0; let days = 0;
let months = 0;
switch (recSplit.period) { switch (recSplit.period) {
case "d": case "d":
days = 1; days = 1;
...@@ -66,12 +67,20 @@ function getRecurrenceDate(due, recurrence) { ...@@ -66,12 +67,20 @@ function getRecurrenceDate(due, recurrence) {
days = 7; days = 7;
break; break;
case "m": case "m":
days = 30; months = 1;
break; break;
case "y": case "y":
days = 365; months = 12;
break; break;
} }
if (months > 0) {
let due_month = due.getMonth() + recSplit.mul * months;
let due_year = due.getFullYear() + Math.floor(due_month/12);
due_month = due_month % 12;
let monthlen = new Date(due_year, due_month+1, 0).getDate();
let due_day = Math.min(due.getDate(), monthlen);
return new Date(due_year, due_month, due_day);
}
due = due.getTime(); due = due.getTime();
due += 1000 * 60 * 60 * 24 * recSplit.mul * days; due += 1000 * 60 * 60 * 24 * recSplit.mul * days;
return new Date(due); return new Date(due);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment