10

I've been using Date.js in my project and recently read a post that moment.js was superior.

However, I'm having trouble believing that it is simply due to the fact that it can't parse input like "5 days from now" to an n actual date.

My personal desire/requirements are that

  1. I can take a variety of inputs (text-fields) and submit them as properly formatted dates.
  2. I can take properly formatted dates and output them as friendly (or just parse them differently).

Date.js does both. Moment.js seems to only do #2...

Am I missing something, or am I cool to use Date.js still?

Additionally...for my rails project. Is it better to format things server-side or client side? ie. I have a few things I'd like to format based on the relative date condition. (Like add a class if it's 10 days from now, or >0 days past now)...pros/cons of client/server side date parsing/manipulation?

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Kevin Brown
  • 12,602
  • 34
  • 95
  • 155
  • 10
    Please be aware of [Datejs's abandonment](http://stackoverflow.com/tags/datejs/info). You may want to use both, but just use Datejs for the portions that momentjs is lacking. – Matt Johnson-Pint Jul 13 '13 at 03:27
  • I've noticed it...in fact, the past few weeks, as I've been working on other issues with my app, I've decided to switch back to moment.js...it's worth giving up the ability to parse input strings... – Kevin Brown Jul 14 '13 at 21:26
  • could you please add an example of something that momentjs can't do. I've recently decided to add momentjs to a project and I find it quite complete... thanks – David Perlman Oct 11 '13 at 08:38
  • 1
    @DavidPerlman, moment.js can't take a variety of inputs like text-fields and submit them as formatted dates, it only takes formats that are already some kind of date...for example, date.js can take strings like 'today' and format them as a date string, whereas moment.js cannot. – Kevin Brown Oct 14 '13 at 20:09
  • 2
    There is a fork of DateJs that is actively maintained: https://github.com/abritinthebay/datejs – srgstm Jan 30 '14 at 03:36
  • Another library that can do this feature that is more stable is [Sugar](http://sugarjs.com/dates). – Matt Johnson-Pint Sep 22 '14 at 23:22

2 Answers2

7

You are correct. Moment.JS does not handle #2 .... only Date.js does.

As for server vs client... I tend to unload calculations to the client unless I am building a mobile app. In the end let the application/project determine where computation should occur.

  • So am I correct in thinking that it would be better to use jquery to conditionally apply classes based on dates relative to today instead of having helper functions in rails to apply them? Is that better practice overall? – Kevin Brown Jun 21 '13 at 20:17
  • Yes, you are correct. I would say that it is best practice to do this on the client-side rather than the server side. In general, any work you can pass to the client I would always do because it will always increase response time. – Johnny Guillen Jul 01 '13 at 17:05
3

It has been 8 years since the question asked. The situation has changed a bit.

momentjs has a web site and github has changes from (Oct 6, 2020). It has a sort of active development stage, when the original Datejs repository has been archived by the owner. Now there is DateJS: Evolved project form abritinthebay that has the latest changes on (Dec 17, 2014)

Bottom line - momentjs is still alive, when Datejs is not.

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191