diff --git a/src/definitions/modules/calendar.js b/src/definitions/modules/calendar.js index 7ff6b4dfd5..925099d75d 100644 --- a/src/definitions/modules/calendar.js +++ b/src/definitions/modules/calendar.js @@ -802,24 +802,32 @@ formattedDate: function (format, date) { return module.helper.dateFormat(format || formatter[settings.type], date || module.get.date()); }, - date: function () { - return module.helper.sanitiseDate($module.data(metadata.date)) || null; + date: function (format) { + return module.helper.dateObjectOrFormatted(format, $module.data(metadata.date)); }, inputDate: function () { return $input.val(); }, - focusDate: function () { - return $module.data(metadata.focusDate) || null; + focusDate: function (format) { + return module.helper.dateObjectOrFormatted(format, $module.data(metadata.focusDate)); }, - startDate: function () { + startDate: function (format) { var startModule = module.get.calendarModule(settings.startCalendar); - return (startModule ? startModule.get.date() : $module.data(metadata.startDate)) || null; + if (startModule) { + return startModule.get.date(format); + } + + return module.helper.dateObjectOrFormatted(format, $module.data(metadata.startDate)); }, - endDate: function () { + endDate: function (format) { var endModule = module.get.calendarModule(settings.endCalendar); - return (endModule ? endModule.get.date() : $module.data(metadata.endDate)) || null; + if (endModule) { + return endModule.get.date(format); + } + + return module.helper.dateObjectOrFormatted(format, $module.data(metadata.endDate)); }, minDate: function () { return $module.data(metadata.minDate) || null; @@ -1135,6 +1143,20 @@ return match.slice(1, -1); }); }, + dateObjectOrFormatted: function (format, date) { + format = format || ''; + date = module.helper.sanitiseDate(date) || null; + + if (!date) { + return null; + } + + if (format === '') { + return date; + } + + return module.helper.dateFormat(format, date); + }, isDisabled: function (date, mode) { return (mode === 'day' || mode === 'month' || mode === 'year' || mode === 'hour') && (((mode === 'day' && settings.disabledDaysOfWeek.indexOf(date.getDay()) !== -1) || settings.disabledDates.some(function (d) { var blocked = false;