All my dates come formatted as ISO 8601 from the backend, eg 2014-01-01T12:45:30Z
. Across the application, I want to display them in different formats...
- shorthand in tables, eg
Jan 1
- longer, more explicit format on a detailed view, eg
Monday, January 1st
.
Solution I made a helper where I can pass in the format. Easy enough.
can.mustache.registerHelper('formatDate', function(date, format) {
return date() ? moment(date()).format(format) : '-';
});
Problem Now I'm implementing the bootstrap datepicker, how can I capture these requirements...
- the date in my model is formatted as ISO
- bind to input with
can-value
in template - display format MM/DD/YY for users and datepicker
Bonus points if I don't need to make a compute for every single date value in my models, as they're quite large and with many dates.