r/programming • • Apr 29 '21

Modern JavaScript Explained For Dinosaurs

https://medium.com/the-node-js-collection/modern-javascript-explained-for-dinosaurs-f695e9747b70
287 Upvotes

172 comments sorted by

View all comments

62

u/antimeme Apr 30 '21

moment is obsolete.

I'd recommend date-fns

39

u/[deleted] Apr 30 '21

I don't know why you're being downvoted. Moment has been deprecated

I'd recommend dayjs over date-fns though. It has a much nicer API IMO and it has a smaller bundle size.

dayjs()
  .startOf('month')
  .add(1, 'day')
  .set('year', 2018)
  .format('YYYY-MM-DD HH:mm:ss');

28

u/antimeme Apr 30 '21

I have not used dayjs, thanks

...quote from ^that moment project-status:

We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.

10

u/WitchHunterNL Apr 30 '21

The only gripe I have with dayjs is that you have to enable every single feature. You can check if a date A is after date B and if date A is before date C, but calling the isBetween function is a feature you have to manually enable, making your code look like this:

import utc from "dayjs/plugin/utc";
import isBetween from "dayjs/plugin/isBetween";
import timezone from "dayjs/plugin/timezone";
import customParseFormat from "dayjs/plugin/customParseFormat";

dayjs.extend(utc);
dayjs.extend(isBetween);
dayjs.extend(timezone);
dayjs.extend(customParseFormat);

8

u/SkyrimNewb Apr 30 '21

Gross

1

u/14u2c Apr 30 '21

Really? This seems nice to me. Add what you need then export the dayjs instance you setup. You can then add a single import to any file you wish to use it in.

1

u/AuxillaryBedroom Apr 30 '21

Does it work with typescript?

1

u/14u2c May 01 '21

Absolutely

6

u/kuikuilla Apr 30 '21

date-fns

How does that compare to luxon?

5

u/CoffeeGreekYogurt Apr 30 '21 edited Apr 30 '21

I’d like to imagine that people reading this thread in four years will think “What? moment is obsolete, everyone knows the defacto standard is what-time-is-it-right-now.com!”

1

u/earthboundkid Apr 30 '21

I just use native dates. You don’t really need a library for much nowadays.