Search code examples
ruby-on-rails-3client-servermomentjsdatejs

Date.js vs Moment.js (and server-side formatting)


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?


Solution

  • 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.