I have this sample code(a .js library needs to be consumed) for formatting the date. Have never used partial functions before so not quite sure how to use it. How does one call them? Here is the utility library code:
define(function() {
'use strict';
function _formatDate(justNowText, todayFormat, thisWeekFormat, thisYearFormat, veryOldFormat, date) {
if (!date) { return ""; }
var formattedMoment = moment(date);
var now = moment();
if (now.diff(formattedMoment, "minutes") < 15) {
return justNowText || "Just now";
}
var today = now.startOf('day');
var dateFormat;
if (today <= formattedMoment) {
dateFormat = todayFormat;
} else if (now.diff(formattedMoment, "days") < 7) {
dateFormat = thisWeekFormat;
} else if (formattedMoment.year() >= now.year()) {
dateFormat = thisYearFormat;
} else {
dateFormat = veryOldFormat;
}
return formattedMoment.format(dateFormat);
}
function asShortTimeStampFilter(gettext) {
return _.partial(_formatDate,
gettext("Just now"),
"h:mm A",
"ddd",
"MMM D",
"M/D/YY"
);
}
function asMediumTimeStampFilter(gettext) {
return _.partial(_formatDate,
gettext("Just now"),
"[" + gettext("Today at") + "] h:mm a",
"ddd h:mm a",_formatDate
"MMM D h:mm a",
"M/D/YYYY h:mm a"
);
}
function asDateTimeFormatFilter(gettext) {
return function(date, format) {
if (!date) { return; }
return moment(date).format(format);
};
}
return {
asShortTimeStamp: ['gettext', asShortTimeStampFilter],
asMediumTimeStamp: ['gettext', asMediumTimeStampFilter],
asDateTimeFormat: ['gettext', asDateTimeFormatFilter]
};
});