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

221
Views
¿Cómo puedo generar los plazos dados 03 parámetros en Google Apps Script?

Dados 3 parámetros, me gustaría saber por qué esto no está iterando/generando las fechas, sino repitiendo la primera iteración.

 //Means 01 installement for tomorrow and the other 6 from tomorrow on every 30 days function generateInstallments() { let condition = '1 + 6x' let firstInstallment = 1;//Tomorrow let intervalInDays = 30; var dueDate = ''; let deadlines = []; if (condition.indexOf('+') > -1) { //If it contains this pattern (1 + 4x) //Extracts the number preceding x, as this will be the number of installments condition= Number(condition.slice( condition.indexOf('+ ') + 2, condition.lastIndexOf('x'), )); let firstInstallementDate = addDays(new Date(), firstInstallment ); deadlines.push(Utilities.formatDate(firstInstallementDate , Session.getTimeZone(), "dd/MM/yyyy")); for (let a = 0; a < condition; a++) { dueDate = addDays(firstInstallementDate , intervalInDays );//Function can be found below deadlines.push(Utilities.formatDate(dueDate, Session.getTimeZone(), "dd/MM/yyyy")); } } }

La primera y las 2 segundas fechas son correctas, pero las otras 4 son las mismas que la segunda, por lo que no itera como se esperaba.

Esta es la función que estoy usando para agregar los días:

 function addDays(date, days) { var result = new Date(date); result.setDate(result.getDate() + days); return result; }

¡Gracias!

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

0

Cuando vi su secuencia de comandos, firstInstallementDate se usa en el bucle. En este caso, el valor de firstInstallementDate no se actualiza. Pensé que esta podría ser la razón de su problema. Si mi comprensión es correcta, ¿qué tal la siguiente modificación?

De:

 for (let a = 0; a < condition; a++) { dueDate = addDays(firstInstallementDate , intervalInDays );//Function can be found below deadlines.push(Utilities.formatDate(dueDate, Session.getTimeZone(), "dd/MM/yyyy")); }

A:

 for (let a = 0; a < condition; a++) { firstInstallementDate = addDays(firstInstallementDate, intervalInDays); deadlines.push(Utilities.formatDate(firstInstallementDate, Session.getTimeZone(), "dd/MM/yyyy")); }
  • Con esta modificación se obtiene el siguiente resultado.

     [ '09/03/2022', '08/04/2022', '08/05/2022', '07/06/2022', '07/07/2022', '06/08/2022', '05/09/2022' ]
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!