2014-04-20 18:48:34 +04:00
|
|
|
/* global moment */
|
2014-10-25 01:09:50 +04:00
|
|
|
// jscs: disable disallowSpacesInsideParentheses
|
|
|
|
|
|
|
|
var parseDateFormats,
|
|
|
|
displayDateFormat,
|
|
|
|
verifyTimeStamp,
|
|
|
|
parseDateString,
|
|
|
|
formatDate;
|
|
|
|
|
|
|
|
parseDateFormats = ['DD MMM YY @ HH:mm', 'DD MMM YY HH:mm',
|
2015-05-13 01:42:02 +03:00
|
|
|
'D MMM YY @ HH:mm', 'D MMM YY HH:mm',
|
2014-06-09 00:48:14 +04:00
|
|
|
'DD MMM YYYY @ HH:mm', 'DD MMM YYYY HH:mm',
|
2015-05-13 01:42:02 +03:00
|
|
|
'D MMM YYYY @ HH:mm', 'D MMM YYYY HH:mm',
|
2014-06-09 00:48:14 +04:00
|
|
|
'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',
|
2014-07-07 06:45:32 +04:00
|
|
|
'YYYY-MM-DD @ HH:mm', 'YYYY-MM-DD HH:mm',
|
2015-05-13 01:42:02 +03:00
|
|
|
'DD MMM @ HH:mm', 'DD MMM HH:mm',
|
|
|
|
'D MMM @ HH:mm', 'D MMM HH:mm'];
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-11-17 20:09:01 +03:00
|
|
|
displayDateFormat = 'DD MMM YY @ HH:mm';
|
2014-04-20 18:48:34 +04:00
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Add missing timestamps
|
|
|
|
verifyTimeStamp = function (dateString) {
|
2014-06-09 00:48:14 +04:00
|
|
|
if (dateString && !dateString.slice(-5).match(/\d+:\d\d/)) {
|
|
|
|
dateString += ' 12:00';
|
|
|
|
}
|
|
|
|
return dateString;
|
|
|
|
};
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Parses a string to a Moment
|
|
|
|
parseDateString = function (value) {
|
2014-06-09 00:48:14 +04:00
|
|
|
return value ? moment(verifyTimeStamp(value), parseDateFormats, true) : undefined;
|
2014-04-20 18:48:34 +04:00
|
|
|
};
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Formats a Date or Moment
|
|
|
|
formatDate = function (value) {
|
2014-06-09 00:48:14 +04:00
|
|
|
return verifyTimeStamp(value ? moment(value).format(displayDateFormat) : '');
|
2014-04-20 18:48:34 +04:00
|
|
|
};
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
export {parseDateString, formatDate};
|