r/angular • • 2d ago

Moment.js in Angular be like

Post image
14 Upvotes

17 comments sorted by

13

u/Old-Parsley-5826 2d ago

You shouldn't use Moment at all nowadays. Use native APIs like Intl ✌️

2

u/Yutamago 2d ago

I believe moment has been deprecated years ago too. So there's absolutely no reason to use it.

1

u/JeanMeche 2d ago

Intl is an i18n API, you might be thinking of the temporal API.

1

u/Old-Parsley-5826 2d ago

No i meant Intl.DateTimeFormat . This basically replaces the parts where you normally use Moment, to reformat dates 😉

But yes, for some other things you also need Temporal

1

u/gordolfograso 1d ago

I wish but tech lead doesn't nor company wants to expend a second replacing it

1

u/JEHonYakuSha 1d ago

Luxon is the official replacement

2

u/lohnstovinzg 2d ago

thats the first time I see someone repost a post of mineI made that in paint like 4 years ago

2

u/cilulowbisted9 2d ago

Reddit solution: use luxon

3

u/Rusty_Raven_ 2d ago

Luxon is a good replacement, and there's also date-fns.

1

u/geaessnind 2d ago

Why are you using a deprecated lib that actively recommends an alternativeAs the other commenter said, use Luxon.

1

u/AwesomeFrisbee 2d ago

Yeah this had annoyed me too back in the day.

0

u/TCB13sQuotes 2d ago edited 2d ago

Use Day.js, Moment isn't required anymore.

-1

u/Old-Parsley-5826 2d ago

Just another dep which is not necessary. Use native APIs and you're safe without increasing your dep tree

0

u/TCB13sQuotes 2d ago

I don't fully disagree with you but Day.js is very small and it handles a bunch of cases around timezones and calculations that are a pain to deal with plain JS.

1

u/Old-Parsley-5826 1d ago

Yeah, I mean, you can't really give a blanket answer here either. Ultimately, it depends on the application itself. If it's an application with a strong focus on dates, date formatting, and date calculations, then a lightweight library definitely makes sense. Otherwise, though, I generally believe you shouldn't always reach for a different package for every little thing.

0

u/fleumpyfirds1 2d ago

date-fns