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

234
Vistas
Divide timespan in JavaScript

I have to recreate some logic from Kusto query language in JS and I'm struggling with duration division. How can I get quotient from two durations, like this :

One can divide two timespan values to get their quotient. For example, 1d / 5h gives 4.8. This gives one the ability to express any timespan value as a multiple of another timespan value. For example, to express an hour in seconds, simply divide 1h by 1s: 1h / 1s (with the obvious result, 3600).

(taken from https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic)

I'm using date-fns, but I'm flexible with libraries.

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

0

You can simply define constants. For example, if the smallest unit you are going to use is 1 seconds, then you can put:

const
  S = 1,
  M = 60,
  H = M * 60,
  D = H * 24,
  W = D * 7;

Now terms like 1s cannot magically become a valid syntax in JavaScript, but expressions like (2 * D) / (10 * H) can work just fine.

(edited the answer to use uppercase for constants as it's a common convention)

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