Files
pedwfrontend/lib/domain/representation-policy/resolveRepresentationWindow.js
T
Robert Bond 7e47340326 Merged PR 2377: added enlarge map view on dnsapplication list
added enlarge map view on dnsapplication list

Related work items: #23774
2026-06-09 10:04:32 +00:00

60 lines
1.7 KiB
JavaScript

const startOfToday = (DateCtor = Date) =>
new DateCtor(new DateCtor().toDateString());
const toDate = (value, DateCtor = Date) => new DateCtor(value);
export function isRepresentationWindowOpen(
startDate,
endDate,
DateCtor = Date
) {
const date = startOfToday(DateCtor);
const start = toDate(startDate, DateCtor);
const end = toDate(endDate, DateCtor);
return date >= start && date <= end ? true : false;
}
export function isRepresentationWindowClosed(
startDate,
endDate,
DateCtor = Date
) {
const date = startOfToday(DateCtor);
const start = toDate(startDate, DateCtor);
const end = toDate(endDate, DateCtor);
return date > start && date > end ? true : false;
}
export function resolveRepresentationWindow(caseDetails, DateCtor = Date) {
caseDetails = caseDetails || {};
const hasStartDate =
Object.prototype.hasOwnProperty.call(caseDetails, "pinswg_startdate") ||
Object.prototype.hasOwnProperty.call(
caseDetails,
"pinswg_applicationacceptedasvalid"
) ||
Object.prototype.hasOwnProperty.call(caseDetails, "pinswg_startdates");
const startDate =
caseDetails.pinswg_startdate ||
caseDetails.pinswg_startdates ||
caseDetails.pinswg_applicationacceptedasvalid;
const endDate =
caseDetails.pinswg_finalcommentsduedate ||
caseDetails.pinswg_endofrepresentationperiod;
return {
hasStartDate,
startDate,
endDate,
isOpen:
hasStartDate &&
isRepresentationWindowOpen(startDate, endDate, DateCtor),
isClosed: isRepresentationWindowClosed(startDate, endDate, DateCtor)
};
}