JSFiddle - React, Tailwind, and code Playground

by borisjavier

JavaScript

const f0 = 1714435200,
f = 1727654400,
pGMonths = 6,
payableMonths = 12

const iniOf = f0;
 console.log('iniOf: ', iniOf)
  const endOf = f - 86400; 
   console.log('endOf: ', endOf)
  const iniProy = f;
  const iniOp = f + (pGMonths * 30 * 86400); // Aproximación de meses a segundos (30 días por mes)
  const endGP = iniOp + (payableMonths * 30 * 86400);
  console.log('endGP: ', endGP);
  const perTot = 2;
  const endPay = endGP + (perTot * 360 * 86400);//2 años
  console.log('endPay: ', endPay)
  
  const now = Math.abs(Date.now()/1000);
console.log('now: ', now)

let next = "onTime-";

  if (now < iniOf) {
    next += "launch";
  } else if (now >= iniOf && now < endOf) {
    next += "endOfr";
  } else if (now >= endOf && now < iniProy) {
    next += "implem";
  } else if (now >= iniProy && now < iniOp) {
    next += "roiBeg";
  } else if (now >= iniOp && now < endGP) {
    next += "roiEnd";
  } else {
    next = "outOfRange"; // O cualquier otro valor que desees para indicar que está fuera de rango.
  }
  
  //console.log('next: ', next)
  const string = next.split('-')[1]
  //console.log('string: ', string)
  
  const fechas = "[{&quot;iniOf&quot;:&quot;2024-04-30&quot;,&quot;endOf&quot;:&quot;2024-09-29&quot;,&quot;iniProy&quot;:&quot;2024-09-30&quot;,&quot;iniOp&quot;:&quot;2025-09-25&quot;,&quot;endGP&quot;:&quot;2026-09-20&quot;,&quot;endPay&quot;:&quot;2028-09-09&quot;}]";
  
  const jsonString = fechas.replace(/&quot;/g, '"');

// Parsear la cadena JSON
const fec = JSON.parse(jsonString);
 //const fec = JSON.parse(fechas);
  
  let result = '';
            let stage = ''
            const currentIndex = 1;

            switch(currentIndex) {
                case 0:
                    result = '<span lang="en" data-lang-token="launchTime">Lanzamiento en: </span>';
                    stage = 'iniOf';
                    break;
                case 1:
                    result = '<span lang="en" data-lang-token="endOfrTime">Termina oferta en:  </span>';
...