gtfs-alerts-utils
Version:
Utilities to work with GTFSrt Alerts
49 lines (43 loc) • 1.36 kB
JavaScript
;
exports.getEarliestStartDate = (entity) => {
const alert = entity.alert;
if (alert) {
const activePeriod = alert.activePeriod;
if (activePeriod) {
if (activePeriod.length === 0) {
return undefined;
}
let earliestStartDate = Number.MAX_SAFE_INTEGER;
for (const timeRange of alert.activePeriod) {
if (!timeRange.start || parseInt(timeRange.start) === 0) { // 0 is the default value
return undefined; // Undefined time range, return this immediately
} else if (earliestStartDate > timeRange.start) {
earliestStartDate = timeRange.start;
}
}
return earliestStartDate;
}
}
return undefined;
};
exports.getLatestEndDate = (entity) => {
const alert = entity.alert;
if (alert) {
const activePeriod = alert.activePeriod;
if (activePeriod) {
if (activePeriod.length === 0) {
return undefined;
}
let latestEndDate = 0;
for (const timeRange of alert.activePeriod) {
if (!timeRange.end || parseInt(timeRange.end) === 0) { // 0 is the default value
return undefined; // Undefined time range, return this immediately
} else if (latestEndDate < timeRange.end) {
latestEndDate = timeRange.end;
}
}
return latestEndDate;
}
}
return undefined;
};