Files
pedwfrontend/components/case/summary/utils/liveEvent.js
T
Robert Bond 9140476a2a Merged PR 2285: tweak to live link
tweak to live link

Related work items: #22423
2026-04-29 17:03:50 +00:00

37 lines
946 B
JavaScript

export function isEventLiveNow(item) {
if (!item?.pinswg_dateeventrequested) return false;
const now = new Date();
const start = new Date(item.pinswg_dateeventrequested);
if (isNaN(start.getTime())) return false;
const endDateValue =
item.pinswg_enddateofevent || item.pinswg_enddateoftheevent;
if (endDateValue) {
const end = new Date(endDateValue);
if (isNaN(end.getTime())) return false;
end.setHours(23, 59, 59, 999);
return now >= start && now <= end;
}
const endOfStartDay = new Date(start);
endOfStartDay.setHours(23, 59, 59, 999);
return now >= start && now <= endOfStartDay;
}
export function getLivePublishedEvent(eventsObj) {
const eventsArr = eventsObj?.value || [];
return eventsArr.find(
(item) =>
item.pinswg_eventpublishflag &&
item.pinswg_linktotheevent &&
isEventLiveNow(item)
);
}