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

459
Views
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
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!