Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
¿Cómo adelantar la fecha más cercana por el número del día de la semana?

Soy nuevo en el momento y necesito adelantar la fecha más cercana por el número del día de la semana.

Dependiendo de la fecha actual, necesito obtener, por ejemplo:

 const currentWeekDay = '4'; (14.04) const preparedAlternativeDates = [ { DAY: 1, VALUE: '18.04' }, { DAY: 2, VALUE: '19.04'}, { DAY: 3, VALUE: '20.04'}, { DAY: 4, VALUE: '21.04'}, { DAY: 5, VALUE: '15.04'}, { DAY: 6, VALUE: '16.04'}, { DAY: 7, VALUE: '17.04'}, ];

Estoy tratando de usar el siguiente script pero no funciona. Tal vez hay una manera más fácil de hacer esto?

 const ALTERNATIVE_DATES = Object.freeze([ { DAY: 1, VALUE: null }, { DAY: 2, VALUE: null }, { DAY: 3, VALUE: null }, { DAY: 4, VALUE: null }, { DAY: 5, VALUE: null }, { DAY: 6, VALUE: null }, { DAY: 7, VALUE: null }, ]); const preparedAlternativeDates = ALTERNATIVE_DATES.map((alternativeDate: any) => { if (!alternativeDate.VALUE) { const alternativeDateDay = Number(alternativeDate.DAY); const currentWeekDay = Number(moment().isoWeekday()); if (alternativeDateDay <= currentWeekDay) { alternativeDate.VALUE = moment().add(alternativeDateDay + currentWeekDay - 1, 'd').startOf('day'); } else { alternativeDate.VALUE = moment().add(alternativeDateDay - currentWeekDay, 'd').startOf('day'); } } return { day: alternativeDate.DAY, value: alternativeDate.VALUE }; });

Estaré agradecido por cualquier ayuda.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Acabo de ajustar su código y probé el resultado. esto debería funcionar para usted:

 const ALTERNATIVE_DATES = Object.freeze([ { DAY: 1, VALUE: null }, { DAY: 2, VALUE: null }, { DAY: 3, VALUE: null }, { DAY: 4, VALUE: null }, { DAY: 5, VALUE: null }, { DAY: 6, VALUE: null }, { DAY: 7, VALUE: null }, ]); const preparedAlternativeDates = ALTERNATIVE_DATES.map((alternativeDate: any) => { if (!alternativeDate.VALUE) { const wishedDay = Number(alternativeDate.DAY); const today = moment().isoWeekday(); if (today < wishedDay) { alternativeDate.VALUE = moment().isoWeekday(wishedDay).format('DD.MM'); } else { alternativeDate.VALUE = moment().add(1, 'weeks').isoWeekday(wishedDay).format('DD.MM'); } } return { day: alternativeDate.DAY, value: alternativeDate.VALUE, }; });

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!