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

461
Visualizações
What is the best way to compare dates with date-fns without locale influence

What is the most proper way of comparing two dates, I have a holidays array from google, and dates fetched from react-day-picker, I transform them to be in JSON format with date.toJSON() method and with the dates from google I get following output:

0: "2020-12-24T00:00:00.000Z"
1: "2020-12-25T00:00:00.000Z"
2: "2021-04-04T00:00:00.000Z"
3: "2022-04-17T00:00:00.000Z"

Their time is zeroed and this is what I would like to end up with, however, when I run .toJSON() method on dates from react-day-picker I get

2021-10-21T10:00:00.000Z
2021-10-27T10:00:00.000Z
2021-10-28T10:00:00.000Z
2021-11-03T11:00:00.000Z
2021-11-04T11:00:00.000Z

they're with the locale time, and then I use date-fns to zero the hours with the set() method like so:

day = set(day, { hours: 0 }).toJSON();
2021-10-19T22:00:00.000Z
2021-10-20T22:00:00.000Z
2021-10-26T22:00:00.000Z
2021-10-27T22:00:00.000Z
2021-11-02T23:00:00.000Z
2021-11-03T23:00:00.000Z
2021-11-09T23:00:00.000Z

so I guess I am unable to get rid of the locale burden, and compare the dates? Or is there a method that could do that for me? Thanks a lot

about 4 years ago · Juan Pablo Isaza
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