Skip to content

Commit

Permalink
feat: refactor period calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusAparicioOrtiz committed Sep 4, 2021
1 parent 0af5f8d commit 8f9c901
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function getTimeZoneOffset(date, timeZone) {
**/
module.exports.getPeriods = function getPeriods(dates, timeZone, filter, Wfrom, Wto) {
let periods = [];

for (var i = 0; i < dates.length - 1; i += 2) {
dates[i + 1].setMilliseconds(999)
dates[i].setUTCHours(dates[i].getUTCHours() + getTimeZoneOffset(dates[i], timeZone))
Expand All @@ -77,6 +78,16 @@ module.exports.getPeriods = function getPeriods(dates, timeZone, filter, Wfrom,
});
}
}

if (dates.length !== 0 && !filter) {
var lastDate = dates[dates.length - 1]
lastDate.setUTCHours(lastDate.getUTCHours() + getTimeZoneOffset(lastDate, timeZone))
periods.push({
from: lastDate.toISOString(),
to: new Date().toISOString()
});
}

return periods;
}

Expand Down

0 comments on commit 8f9c901

Please sign in to comment.