Adds javascript function for rendering a date according to user preference

This commit is contained in:
Oliver 2022-02-28 16:10:16 +11:00
parent b19719516b
commit c720c75b79

View File

@ -7,6 +7,7 @@
clearEvents,
endDate,
startDate,
renderDate,
*/
/**
@ -32,3 +33,29 @@ function clearEvents(calendar) {
event.remove();
});
}
/*
* Render the provided date in the user-specified format.
*
* The provided "date" variable is a string, nominally ISO format e.g. 2022-02-22
* The user-configured setting DATE_DISPLAY_FORMAT determines how the date should be displayed.
*/
function renderDate(date) {
if (!date) {
return null;
}
var fmt = user_settings.DATE_DISPLAY_FORMAT || 'YYYY-MM-DD';
var m = moment(date);
if (m.isValid()) {
return m.format(fmt);
} else {
// Invalid input string, simply return provided value
return date;
}
}