digitransit-ui/app/util/patternUtils.js
2025-06-03 16:15:09 +03:00

17 lines
546 B
JavaScript

import { DateTime } from 'luxon';
/**
Helper for determining is current date in active dates.
Return false if pattern doesn't have active dates information available
or if current day is not found in active days
* */
export const isActiveDate = pattern => {
if (!pattern || !pattern.activeDates) {
return false;
}
const activeDates = pattern.activeDates.reduce((dates, activeDate) => {
return dates.concat(activeDate.day);
}, []);
const now = DateTime.now().toFormat('yyyyLLdd');
return activeDates.indexOf(now) > -1;
};