diff --git a/InvenTree/templates/js/dynamic/calendar.js b/InvenTree/templates/js/dynamic/calendar.js index 268337bd52..c730446bfb 100644 --- a/InvenTree/templates/js/dynamic/calendar.js +++ b/InvenTree/templates/js/dynamic/calendar.js @@ -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; + } +}