hariKerja.js 411 B

12345678910111213141516
  1. exports.hariKerja = (n, fromDate = null) => {
  2. const today = fromDate ? new Date(fromDate) : new Date()
  3. let dayCount = 0;
  4. while (dayCount < n) {
  5. // Pindahkan ke hari berikutnya
  6. today.setDate(today.getDate() + 1);
  7. // Periksa apakah hari saat ini adalah hari (sabtu || minggu)
  8. if (today.getDay() !== 6 && today.getDay() !== 7) {
  9. dayCount++;
  10. }
  11. }
  12. return today.toISOString();
  13. }