60 lines
1.7 KiB
JavaScript
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)
|
|
};
|
|
}
|