Ghost/core/client/app/utils/date-formatting.js
Alex Kleissner 25460b5387 Allow setting a post date using a single digit day.
closes #5248
- added new valid formats for the date formatter
- only the date formats where a single digit day makes sense were
changed
2015-05-12 15:42:02 -07:00

43 lines
1.4 KiB
JavaScript

/* global moment */
// jscs: disable disallowSpacesInsideParentheses
var parseDateFormats,
displayDateFormat,
verifyTimeStamp,
parseDateString,
formatDate;
parseDateFormats = ['DD MMM YY @ HH:mm', 'DD MMM YY HH:mm',
'D MMM YY @ HH:mm', 'D MMM YY HH:mm',
'DD MMM YYYY @ HH:mm', 'DD MMM YYYY HH:mm',
'D MMM YYYY @ HH:mm', 'D MMM YYYY HH:mm',
'DD/MM/YY @ HH:mm', 'DD/MM/YY HH:mm',
'DD/MM/YYYY @ HH:mm', 'DD/MM/YYYY HH:mm',
'DD-MM-YY @ HH:mm', 'DD-MM-YY HH:mm',
'DD-MM-YYYY @ HH:mm', 'DD-MM-YYYY HH:mm',
'YYYY-MM-DD @ HH:mm', 'YYYY-MM-DD HH:mm',
'DD MMM @ HH:mm', 'DD MMM HH:mm',
'D MMM @ HH:mm', 'D MMM HH:mm'];
displayDateFormat = 'DD MMM YY @ HH:mm';
// Add missing timestamps
verifyTimeStamp = function (dateString) {
if (dateString && !dateString.slice(-5).match(/\d+:\d\d/)) {
dateString += ' 12:00';
}
return dateString;
};
// Parses a string to a Moment
parseDateString = function (value) {
return value ? moment(verifyTimeStamp(value), parseDateFormats, true) : undefined;
};
// Formats a Date or Moment
formatDate = function (value) {
return verifyTimeStamp(value ? moment(value).format(displayDateFormat) : '');
};
export {parseDateString, formatDate};