Skip to content

Commit

Permalink
Extended periods
Browse files Browse the repository at this point in the history
Signed-off-by: Faisal N <[email protected]>
  • Loading branch information
faisalnjs authored Jan 21, 2025
1 parent 9dbfb69 commit cdc6257
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/periods/periods.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import schedule from "./schedule.json";
import extendedSchedule from "./extendedSchedule.json";

const timestamps = schedule.map((period) => {
return [timeToMs(period[0]), timeToMs(period[1])];
});

const extendedTimestamps = extendedSchedule.map((period) => {
return [timeToMs(period[0]), timeToMs(period[1])];
});

// Returns zero-indexed period
export function getPeriod(date) {
date = date || Date.now();
Expand All @@ -13,6 +18,14 @@ export function getPeriod(date) {
return period;
}

export function getExtendedPeriod(date) {
date = date || Date.now();
const period = extendedTimestamps.findIndex((periods) => {
return date >= periods[0] && date < periods[1];
});
return period;
}

// Converts hh:mm to milliseconds
export function timeToMs(time) {
const now = new Date();
Expand Down

0 comments on commit cdc6257

Please sign in to comment.