mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
2f4f6db133
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
/* global moment */
|
|
// jscs: disable disallowSpacesInsideParentheses
|
|
|
|
const 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'];
|
|
|
|
const displayDateFormat = 'DD MMM YY @ HH:mm';
|
|
|
|
// Add missing timestamps
|
|
function verifyTimeStamp(dateString) {
|
|
if (dateString && !dateString.slice(-5).match(/\d+:\d\d/)) {
|
|
dateString += ' 12:00';
|
|
}
|
|
return dateString;
|
|
}
|
|
|
|
// Parses a string to a Moment
|
|
function parseDateString(value) {
|
|
return value ? moment(verifyTimeStamp(value), parseDateFormats, true) : undefined;
|
|
}
|
|
|
|
// Formats a Date or Moment
|
|
function formatDate(value) {
|
|
return verifyTimeStamp(value ? moment(value).format(displayDateFormat) : '');
|
|
}
|
|
|
|
export {
|
|
parseDateString,
|
|
formatDate
|
|
};
|