settlement-date.ts
1 export function nextMainnetSettlementDate() { 2 const currentDate = new Date(); 3 4 let lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0); 5 6 if (lastDay.getDay() < 4) { 7 lastDay.setDate(lastDay.getDate() - 7); 8 } 9 10 lastDay.setDate(lastDay.getDate() - (lastDay.getDay() - 4)); 11 12 if (currentDate > lastDay) { 13 lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 2, 0); 14 if (lastDay.getDay() < 4) { 15 lastDay.setDate(lastDay.getDate() - 7); 16 } 17 lastDay.setDate(lastDay.getDate() - (lastDay.getDay() - 4)); 18 } 19 20 return lastDay; 21 }