DEV Community

Discussion on: Can I Get Some Feedback? (Moment.js in particular)

Collapse
 
daviddalbusco profile image
David Dal Busco • Edited

Instead of format I would maybe rather use the calendar view?

I personally rather like to read "Your expected ship date is tomorrow at 9:09 AM" than "Your expected ship date is 2019 11th May 09:09 AM"

moment(expectedProcessing).calendar(); 

About the calculation there is a moment().weekday(); method. Not sure if fits your use case but maybe you don't have to create an array of available dates.

Also I would maybe not initializeexpectedProcessing to a string (expectedProcessing = "") as it will be soon afterwards be transformed in a date.

About cloning dates, I never used that method and I ask my self if it isn't a bit less performant than just creating a new Date() specially as you are interested on knowing "today".

Finally, does the comparison now > todaysCutoff always work? isn't that comparing two objects references? When I compare dates I always compare their time so I'm sure the comparison will work, something like the following or as James Kenaley suggested with isBefore

if (now.toDate().getTime() > todaysCutoff.toDate().getTime()) {
    // something
}

Final thought, if I may of course, Moment.js is really handy and the calendar view and i18n is really nice but, that being said, if you only use Moment for that purpose your clients will have to fetch a lot of Javascript code just for that purpose. In such cases you might want to have a look to other lighter date manipulation library like date-fns or others