R62 A1-A6:2026年中国法定假期日历
这个提交包含在:
+44
-18
@@ -134,46 +134,71 @@ function countHalfDayUnitsForDate({ date, startDate, endDate, startSession, endS
|
||||
return 2;
|
||||
}
|
||||
|
||||
function calculateRequestedDaysByWorkingCalendar({
|
||||
function calculateRequestedDaysPreviewByWorkingCalendar({
|
||||
startDate,
|
||||
endDate,
|
||||
startSession,
|
||||
endSession,
|
||||
calendarDays = [],
|
||||
}) {
|
||||
const startSlot = toHalfDaySlot(startDate, startSession);
|
||||
const endSlot = toHalfDaySlot(endDate, endSession);
|
||||
|
||||
if (endSlot < startSlot) {
|
||||
throw buildLeaveValidationError({ leave: "invalid_range" });
|
||||
}
|
||||
const naturalRequestedDays = calculateRequestedDays({
|
||||
startDate,
|
||||
endDate,
|
||||
startSession,
|
||||
endSession,
|
||||
});
|
||||
|
||||
const calendarDayMap = buildHolidayCalendarDayMap(calendarDays);
|
||||
const current = normalizeDateOnly(startDate);
|
||||
const finalDate = normalizeDateOnly(endDate);
|
||||
let cursor = current;
|
||||
let totalUnits = 0;
|
||||
let requestedUnits = 0;
|
||||
let holidayUnits = 0;
|
||||
let weekendUnits = 0;
|
||||
let adjustedWorkdayUnits = 0;
|
||||
|
||||
while (cursor.getTime() <= finalDate.getTime()) {
|
||||
if (isWorkingDateByCalendar(cursor, calendarDayMap)) {
|
||||
totalUnits += countHalfDayUnitsForDate({
|
||||
date: cursor,
|
||||
startDate,
|
||||
endDate,
|
||||
startSession,
|
||||
endSession,
|
||||
});
|
||||
const units = countHalfDayUnitsForDate({
|
||||
date: cursor,
|
||||
startDate,
|
||||
endDate,
|
||||
startSession,
|
||||
endSession,
|
||||
});
|
||||
const dateKey = formatDateOnly(cursor);
|
||||
const configuredType = calendarDayMap.get(dateKey) ?? null;
|
||||
|
||||
if (configuredType === "holiday") {
|
||||
holidayUnits += units;
|
||||
} else if (!isWorkingDateByCalendar(cursor, calendarDayMap)) {
|
||||
weekendUnits += units;
|
||||
} else {
|
||||
requestedUnits += units;
|
||||
if (configuredType === "adjusted_workday") {
|
||||
adjustedWorkdayUnits += units;
|
||||
}
|
||||
}
|
||||
|
||||
cursor = new Date(`${formatDateOnly(cursor)}T00:00:00.000Z`);
|
||||
cursor.setUTCDate(cursor.getUTCDate() + 1);
|
||||
}
|
||||
|
||||
if (totalUnits <= 0) {
|
||||
if (requestedUnits <= 0) {
|
||||
throw buildLeaveValidationError({ leave: "non_working_range" });
|
||||
}
|
||||
|
||||
return fromHalfDayUnits(totalUnits);
|
||||
return {
|
||||
requestedDays: fromHalfDayUnits(requestedUnits),
|
||||
naturalRequestedDays,
|
||||
holidayDayCount: fromHalfDayUnits(holidayUnits),
|
||||
weekendDayCount: fromHalfDayUnits(weekendUnits),
|
||||
adjustedWorkdayCount: fromHalfDayUnits(adjustedWorkdayUnits),
|
||||
calendarApplied: true,
|
||||
};
|
||||
}
|
||||
|
||||
function calculateRequestedDaysByWorkingCalendar(input) {
|
||||
return calculateRequestedDaysPreviewByWorkingCalendar(input).requestedDays;
|
||||
}
|
||||
|
||||
function leaveRangesOverlap(left, right) {
|
||||
@@ -573,6 +598,7 @@ module.exports = {
|
||||
DEFAULT_ATTACHMENT_MIME_TYPES,
|
||||
calculateRequestedDays,
|
||||
calculateRequestedDaysByWorkingCalendar,
|
||||
calculateRequestedDaysPreviewByWorkingCalendar,
|
||||
createLeaveLedgerEntry,
|
||||
consumeReservedLeave,
|
||||
currentLeavePeriod,
|
||||
|
||||
在新工单中引用
屏蔽一个用户