Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
given a date and a cron expression can you validate that the date is part of the cron expression

I have a cron expression and i need to check if a certain Date is part of it.(meaning the cron would trigger at that Date) (using nodejs)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use cron-parser package and do something like this:

const isDateMatchesCronExpression = (expression, date, scope = 'second') => {
  scope = ['second', 'minute', 'hour', 'day', 'month', 'weekday'].indexOf(scope.toLowerCase());
  try {
    const data = cronParser.parseExpression(expression).fields;

    if (scope <= 0 && !data.second.includes(date.getSeconds())) return false;
    if (scope <= 1 && !data.minute.includes(date.getMinutes())) return false;
    if (scope <= 2 && !data.hour.includes(date.getHours())) return false;
    if (scope <= 3 && !data.dayOfMonth.includes(date.getDate())) return false;
    if (scope <= 4 && !data.month.includes(date.getMonth() + 1)) return false;
    if (scope <= 5 && !data.dayOfWeek.includes(date.getDay())) return false;

    return true;
  } catch (e) {
    throw new Error(`isDateMatchesCronExpression error: ${e}`);
  }
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda