Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda