58
JavaScript Temporal is coming (developer.mozilla.org)
submitted 4 months ago by [email protected] to c/[email protected]
top 7 comments
sorted by: hot top new old
[-] [email protected] 18 points 4 months ago

I'll be very happy to not have to use Date any more. Pop quiz, what's in whatnum?

const vday = new Date('14 February 2025');
const whatnum = vday.getDay() - vday.getMonth();

Err, it's 5... Ha, amazing; that's not even the gotcha I meant to demonstrate. getDay returns the day of the week, the day of the month is returned from getDate.

Take two:

const vday = new Date('14 February 2025');
const whatnum = vday.getDate() - vday.getMonth();

So this is 14 - 2 = 12, right? Nope! The day (from getDate) is 1-based whereas month is 0-based, so 14 - 1 = 13.

[-] [email protected] 6 points 4 months ago

Man, I can't remember the last time I used Date. I either use moment or... the other big one. I think it's just a three letter name?

[-] [email protected] 2 points 4 months ago

date-fns? It's third in my search results but doesn't ring any bells to me.

[-] [email protected] 6 points 4 months ago

Day.js possibly. It’s a near drop-in for moment since moment is deprecated.

[-] [email protected] 3 points 4 months ago

Yeah, that one! It's a pretty nice library. The difference between it and moment is that date-fns operates on standard Date objects, rather than having its own type

[-] [email protected] 4 points 4 months ago

I'm quite lucky because I only had to solve an issue with JavaScript dates once, but what a nightmare it was… I had to understand how timezones worked, that was not fun!

[-] [email protected] 3 points 4 months ago

Thank god. I've been regularly checking the Github page waiting for it to finally land in browsers. Can hopefully start using the pollyfill for it soon.

this post was submitted on 24 Jan 2025
58 points (100.0% liked)

JavaScript

2367 readers
1 users here now

founded 2 years ago
MODERATORS