Usecase:
If the input day of D1 record is greater than the day of the value date of RH record, the year and month should be set at 1 month before the value date of RH record.
(Note: Input day may be any day of the month i.e. 01 to 31,
but value date can only be a working day, i.e. Monday to Saturday except public holidays)
Example 1:
If input day = 25, value date of RH record = 20020926 (Thursday)
Then the input date is derived as 20020925 (Wednesday)
Example 2:
If input day = 31, value date of RH record = 20020902 (Monday)
Then the input date is derived as 20020831 (Saturday)
Example 3:
If input day = 31, value date of RH record = 20030102 (Thursday)
Then the input date is derived as 20021231 (Tuesday)
Example 4:
If input day = 31, value date of RH record = 20030204 (Tuesday)
Then the input date is derived as 20030131 (Friday)
Example 5:
If input day = 25, value date of RH record = 20250104
Then the input date is derived as 20241226
Javascript codes used:
function deriveInputDate1(inputDay, rhValueDate, publicHolidays) {
// Convert rhValueDate to a Date object
const rhDate = new Date(rhValueDate.slice(0, 4), rhValueDate.slice(4, 6) - 1, rhValueDate.slice(6));
// If inputDay is greater than the day of rhDate, adjust the year and month
if (inputDay > rhDate.getDate()) {
rhDate.setMonth(rhDate.getMonth() - 1);
}
// Set the date to the inputDay
rhDate.setDate(inputDay);
// Ensure the date is a working day (Monday to Saturday, excluding public holidays)
// Sunday is a non-working day
while (rhDate.getDay() === 0 || isPublicHoliday(rhDate, publicHolidays)) {
rhDate.setDate(rhDate.getDate() + 1);
}
// Format the derived date as YYYYMMDD
const derivedDate = rhDate.getFullYear() +
('0' + (rhDate.getMonth() + 1)).slice(-2) +
('0' + rhDate.getDate()).slice(-2);
return derivedDate;
}
// Helper function to check if a date is a public holiday
function isPublicHoliday(date, publicHolidays) {
// Format the date as YYYY-MM-DD for comparison
const formattedDate = date.getFullYear() +
('0' + (date.getMonth() + 1)).slice(-2) +
('0' + date.getDate()).slice(-2);
return publicHolidays.includes(formattedDate);
}
Screenshot of the code:
OIC steps for integration creation:
No comments:
Post a Comment