Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 974
Kevin Brown Avatar asked Jun 21 '13 19:06

Kevin Brown


2 Answers

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.

like image 154
Johnny Guillen Avatar answered Nov 18 '22 17:11

Johnny Guillen


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.

like image 39
Yevgeniy Afanasyev Avatar answered Nov 18 '22 19:11

Yevgeniy Afanasyev