mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
b1176a8a67
Closes #2845. Ref #1351. - Refactored `PostSettingsMenuController` to appropriately set and display slug and publish date and their placeholders. - Removed api spam on title change by putting `slugPlaceholder` generation inside of an `Ember.run.debounce` call. - Renamed `gh-blur-text-field` to `gh-blur-input` - Created `SlugGenerator` class to abstract slug generation. - Added `timestampVerification` function to `utils/date-formatting` - `utils/date-formatting` now uses `strict` parsing of dates - Added more acceptable date formats to accommodate strict parsing - Moved `isDraft` and `isPublished` computed properties from `EditorController` to `PostModel`
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
/* global moment */
|
|
var parseDateFormats = ['DD MMM YY @ HH:mm', 'DD MMM YY HH:mm',
|
|
'DD MMM YYYY @ HH:mm', 'DD 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'],
|
|
displayDateFormat = 'DD MMM YY @ HH:mm';
|
|
|
|
/**
|
|
* Add missing timestamps
|
|
*/
|
|
var verifyTimeStamp = function (dateString) {
|
|
if (dateString && !dateString.slice(-5).match(/\d+:\d\d/)) {
|
|
dateString += ' 12:00';
|
|
}
|
|
return dateString;
|
|
};
|
|
|
|
//Parses a string to a Moment
|
|
var parseDateString = function (value) {
|
|
return value ? moment(verifyTimeStamp(value), parseDateFormats, true) : undefined;
|
|
};
|
|
|
|
//Formats a Date or Moment
|
|
var formatDate = function (value) {
|
|
return verifyTimeStamp(value ? moment(value).format(displayDateFormat) : '');
|
|
};
|
|
|
|
export {parseDateString, formatDate}; |