Live data from Hacker News

Luxon – A library for working with dates and times in JS

github.com

31–40 of 80 posts

Re: Luxon – A library for working with dates and times in JS

#31
So it's a better moment made by the moment team:

https://moment.github.io/luxon/docs/manual/faq/moment.html

Major differences:

  * Immutable
  * Months in Luxon are 1-indexed instead of 0-indexed like in Moment and the native Date type.
  * Localizations and time zones are implemented by the native Intl API (or a polyfill of it), instead of by the library itself.
  * Luxon has both a Duration type and an Interval type. The Interval type is like Twix.
  * Luxon lacks the relative time features of Moment and will until the required facilities are provided by the browser.

Re: Luxon – A library for working with dates and times in JS

#32
post #24

Months in Luxon are 1-indexed instead of 0-indexed like in Moment and the native Date type. This seems like a bold decision and terrifying source of errors for those of us with decades of experience thinking January is 0.

ISO 8601 say January is 01

Jeez, to think I've been using base 10 this whole time!

Re: Luxon – A library for working with dates and times in JS

#34
post #31

So it's a better moment made by the moment team: https://moment.github.io/luxon/docs/manual/faq/moment.html Major differences: * Immutable * Months in Luxon are 1-indexed instead of 0-indexed like in Moment and the native Date type. * Localizations and time zones are implemented by the native Intl API (or a polyfill of it), instead of by the library itself. * Luxon has both a Duration type and an Interval type. The I…

This is an excellent rewrite, but I'm hesitant to try it because Moment doesn't emphasize speed.

I'm in need of a fast date and time library (close to realtime) and have reluctantly rolled my own until I find a better option.

Re: Luxon – A library for working with dates and times in JS

#35
post #4
post #3

Earlier quoted context omitted.

There's a page explaining this: https://moment.github.io/luxon/docs/manual/faq/why.html

Thanks. This link should be on the github page to be honest. For people like me who do not (always) click through if they don’t see an immediate need. Only now notice the url contains moment and this is part of moment.

It is linked on the Github page. There's also a link to a page making direct feature comparisons to Moment: https://moment.github.io/luxon/docs/manual/faq/moment.html

Re: Luxon – A library for working with dates and times in JS

#36
post #26

Sorry for the dumb questions, I haven't worked with js much, but what does this add to the standard library? Going just by the one example there, I can see that timezone by location is probably extra, that's perfectly fine. The endOf modifier seems more like a helper to fix broken date/time model in js? But other parts should probably be in the standard library? I was under the impression js is improving fast nowaday…

The standard library is really difficult to work with and does very little for you. There are some improvements to Dates coming through the standards pipeline but it will be a while.

Re: Luxon – A library for working with dates and times in JS

#37

Months in Luxon are 1-indexed instead of 0-indexed like in Moment and the native Date type. This seems like a bold decision and terrifying source of errors for those of us with decades of experience thinking January is 0.

I think that moment.js was already built that way. For me it kinda makes sense: if days are calculated with a 1-index in mind, why make months different? As I said: it KINDA makes sense.

No, they're 0-indexed in Moment. But yes, the reason I made Luxon 1-index them is that days and years are 1-indexed. I also fielded a lot of issues in Moment that were caused by newer programmers not knowing that months were 0-indexed.

Re: Luxon – A library for working with dates and times in JS

#38
post #11

How does this compare in file size to Moment? That's the only real issue I have with it.

After minification with Uglify: 27.3 KB compressed with `gzip -9`, 26.4KB with `zopfli -i1000` and 24.0KB with `brotli -q 11`. (kilo, not kibi)

I'd love to make it smaller. Several of the builds contain polyfills for newish JS features not supported in IE. I'd like to strip that out and shave off a few k.

Re: Luxon – A library for working with dates and times in JS

#39
post #31

So it's a better moment made by the moment team: https://moment.github.io/luxon/docs/manual/faq/moment.html Major differences: * Immutable * Months in Luxon are 1-indexed instead of 0-indexed like in Moment and the native Date type. * Localizations and time zones are implemented by the native Intl API (or a polyfill of it), instead of by the library itself. * Luxon has both a Duration type and an Interval type. The I…

This is an excellent rewrite, but I'm hesitant to try it because Moment doesn't emphasize speed. I'm in need of a fast date and time library (close to realtime) and have reluctantly rolled my own until I find a better option.

For what it's worth, there's no code (edit: well, maybe a few lines) in common between the libraries; Luxon is written from scratch. I haven't done a ton of perf testing, but depending on your use case, I'd expect most operations to be much faster in Luxon. The caveat there is that Moment objects are mutable, which can sometimes be a perf advantage.
Post reply on HN