Web Analytics
 Contoh function n8n untuk membatasi waktu schedule Trigger jam 1 - 5 Subuh

Contoh function n8n untuk membatasi waktu schedule Trigger jam 1 - 5 Subuh


function getWIBTime() {
  const now = new Date();
  const offset = 7 * 60 * 60 * 1000;
  const wibTime = new Date(now.getTime() + offset);

  const pad = (n) => n.toString().padStart(2, '0');
  const hh = pad(wibTime.getUTCHours());
  const mm = pad(wibTime.getUTCMinutes());
  const ss = pad(wibTime.getUTCSeconds());

  return { hour: wibTime.getUTCHours(), timeStr: `${hh}:${mm}:${ss}` };
}

function getWIBPlusOneHour() {
  const now = new Date();
  const offset = 7 * 60 * 60 * 1000;
  const wibTime = new Date(now.getTime() + offset);
  const plusOneHour = new Date(wibTime.getTime() + (1 * 60 * 60 * 1000));

  const pad = (n) => n.toString().padStart(2, '0');
  const hh = pad(plusOneHour.getUTCHours());
  const mm = pad(plusOneHour.getUTCMinutes());
  const ss = pad(plusOneHour.getUTCSeconds());

  return `${hh}:${mm}:${ss}`;
}

const wibNow = getWIBTime();

if (wibNow.hour >= 1 && wibNow.hour < 5) {
  // Jangan teruskan ke AI jika jam 01:00 - 04:59 WIB
  return [];
} else {
  return [{
    json: {
      time_wib_now: wibNow.timeStr,
      time_wib_plus_1hour: getWIBPlusOneHour()
    }
  }];
}


Lanjut Part : 1
Jam : 04:24:27
Durasi Part : 0:0:1
Durasi Total : 0:0:1

Punya Pertanyaan , Silahkan Whatsapp Langsung
Muhammad Ullil Fahri
WA : 089696380422
Tautan WA : https://wa.me/message/SG4YA2XQP5FPE1