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

139
Views
Why is the Date constructor behaving not as expected for the month index as it does for strings

I have a typescript project were I was getting an error around new years. I wrote a simple jest test like this:

const a = new Date(2022, 0, 1);
const b = new Date("2022-01-01");
expect(a).toEqual(b);

and I got FAILED because

// a is "Sat Jan 01 2022 00:00:00 GMT+0100 (Central European Standard Time)"
// b is "Sat Jan 01 2022 01:00:00 GMT+0100 (Central European Standard Time)"

see the difference in time?

jest test screenshot

What do I not get? It looks to me like this should not happen. Is there a reason for this? thanks so much for your input! happy new year 2022 :)

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!