Live data from Hacker News

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

github.com

71–80 of 80 posts

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

#71
post #66
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…

In what situation is immutable important?

I think there are lots of good reasons to make datetimes immutable (e.g. many of the same reasons most languages make strings immutable). But here's one specific to Moment and Luxon: chainable APIs should really always have immutable types because the return value is the thing you use next anyway. When each call returns an instance of the type it's both completely unnecessary and very often harmful for those calls to modify anything.

  var a = moment();
  console.log("the end of tomorrow is", a.add(1, 'day').endOf('day'));

  // do more stuff with a
  // oh crap, a is now set to tomorrow? wtf?
If you want a to be the end of tomorrow, all you needed to do was assign a to the whole chain, so this mutation didn't help you. That add() and endOf() return instances of Moment signals that they are Moment -> Moment functions, not mutators that also return the object. A mutable API should have void methods:

  var a = moment();
  a.add(1, 'day');
  a.endOf('day');

  // do stuff with a

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

#72
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)

So actually larger than moment (which is 16.3kb gzip)? Hopefully it will improve over time.

API looks better than moment though.

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

#73

Luxon author here, happy to answer anything. Edit: Here's a thing I wrote about why this exists: https://moment.github.io/luxon/docs/manual/faq/why.html

When can you make a Python version available? Datetime is by far my biggest gripe with Python. It takes many times the lines of code to do something “simple” with it vs other languages (e.g. parse remote time stamp in a specific format, apppend time zone info to that, get local time + zone, normalize both to UTC, compare, present difference in human-readable format). Here’s the python version of moment: https://githu…

I'm not much of a Python person, but it seems like someone could port it without too much trouble. In particular, you wouldn't have to use the ugly tricks I used to make the time zone stuff work

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

#74

Earlier quoted context omitted.

When can you make a Python version available? Datetime is by far my biggest gripe with Python. It takes many times the lines of code to do something “simple” with it vs other languages (e.g. parse remote time stamp in a specific format, apppend time zone info to that, get local time + zone, normalize both to UTC, compare, present difference in human-readable format). Here’s the python version of moment: https://githu…

Have you tried arrow (my favorite), dolorean or a third one the name escapes me right now? I use arrow whenever I need to process a date, no matter the usage. Having a consistent interface is golden. EDIT I just realized that the author of moment in Python (you link to) also mentions arrow. I have to remember the name of the third package, it addressed some weaknesses in arrow (particularly issues with failed parsing…

Possibly https://github.com/kennethreitz/maya

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

#75
post #30

Earlier quoted context omitted.

I my experience the actual timezone information is the heaviest portion of the payload. I can't wait until all browsers have support for `Intl`

That any computers talk to each other about time in any other terms than epoch is insane to me. From there, converting it to local time zone is pretty easy, but it should be a presentation-layer ONLY thing. If you’ve ever worked with or implemented a system where this wouldn’t work, I’m interested in hearing about why.

That anyone uses UTC for anything where it isn't relevant is insane to me. If I schedule a meeting in local time, then it's in local time. It has nothing to do with UTC. It's local time at the beginning, middle and end.

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

#76

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.

Months should always be 1-indexed. Years are, days are, why not months?

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

#77
post #66
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…

In what situation is immutable important?

Mutability invites bugs, so immutability is important in the general case, not in special situations.

https://rjbs.manxome.org/rubric/entry/1929

https://blog.plover.com/prog/perl/DateTime-Moonpig.html

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

#78
post #13
post #7

PLEASE use joda-js on Javascript: https://js-joda.github.io/js-joda/ It's a port of the java8 date/time API, which is the most correct date-handling library there is.

What if one does not want to use a port of Joda? Even looking at the documentation makes me run away. Where are all the examples? date-fns seems good, moment works well too, despite its flaws, this new one is worth looking at. Dismissing all other libraries isn't very helpful. And yes, I realise all other libraries are wrappers around Date. It works well enough for 99% of cases.

Date-handling should work in 100% of cases.

You can built syntactic sugar around js-joda too.

I develop Java/kotlin as well, so I'm used to the API. It feels verbose, but it makes a lot of sense. Date-handling is complex, a library shouldn't hide that.

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

#79
post #78
post #13

Earlier quoted context omitted.

What if one does not want to use a port of Joda? Even looking at the documentation makes me run away. Where are all the examples? date-fns seems good, moment works well too, despite its flaws, this new one is worth looking at. Dismissing all other libraries isn't very helpful. And yes, I realise all other libraries are wrappers around Date. It works well enough for 99% of cases.

Date-handling should work in 100% of cases. You can built syntactic sugar around js-joda too. I develop Java/kotlin as well, so I'm used to the API. It feels verbose, but it makes a lot of sense. Date-handling is complex, a library shouldn't hide that.

That's not what I meant by "works". I meant works for the use case. Moment has worked 100% for me whenever I used it. It's API is simple and does what it says.

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

#80

Earlier quoted context omitted.

Have you tried arrow (my favorite), dolorean or a third one the name escapes me right now? I use arrow whenever I need to process a date, no matter the usage. Having a consistent interface is golden. EDIT I just realized that the author of moment in Python (you link to) also mentions arrow. I have to remember the name of the third package, it addressed some weaknesses in arrow (particularly issues with failed parsing…

Possibly https://github.com/kennethreitz/maya

I remember, it was Pendulum, https://github.com/sdispater/pendulum/
Post reply on HN