Added timeShift() function, closes #307.

This commit is contained in:
Alexander Zobnin
2016-11-17 17:48:08 +03:00
parent 092b6c897c
commit 54c03e6ece
4 changed files with 84 additions and 6 deletions

View File

@@ -59,6 +59,20 @@ export function parseInterval(interval) {
return moment.duration(Number(momentInterval[1]), momentInterval[2]).valueOf();
}
export function parseTimeShiftInterval(interval) {
let intervalPattern = /^([\+\-]*)([\d]+)(y|M|w|d|h|m|s)/g;
let momentInterval = intervalPattern.exec(interval);
let duration = 0;
if (momentInterval[1] === '+') {
duration = 0 - moment.duration(Number(momentInterval[2]), momentInterval[3]).valueOf();
} else {
duration = moment.duration(Number(momentInterval[2]), momentInterval[3]).valueOf();
}
return duration;
}
/**
* Format acknowledges.
*