2014-04-20 18:48:34 +04:00
|
|
|
/* global moment */
|
2014-06-09 00:48:14 +04:00
|
|
|
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',
|
2014-07-07 06:45:32 +04:00
|
|
|
'YYYY-MM-DD @ HH:mm', 'YYYY-MM-DD HH:mm',
|
|
|
|
'DD MMM @ HH:mm', 'DD MMM HH:mm'],
|
2014-04-20 18:48:34 +04:00
|
|
|
displayDateFormat = 'DD MMM YY @ HH:mm';
|
|
|
|
|
2014-06-09 00:48:14 +04:00
|
|
|
/**
|
|
|
|
* Add missing timestamps
|
|
|
|
*/
|
|
|
|
var verifyTimeStamp = function (dateString) {
|
|
|
|
if (dateString && !dateString.slice(-5).match(/\d+:\d\d/)) {
|
|
|
|
dateString += ' 12:00';
|
|
|
|
}
|
|
|
|
return dateString;
|
|
|
|
};
|
|
|
|
|
2014-04-20 18:48:34 +04:00
|
|
|
//Parses a string to a Moment
|
|
|
|
var 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
|
|
|
};
|
|
|
|
|
|
|
|
//Formats a Date or Moment
|
|
|
|
var 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-06-09 00:48:14 +04:00
|
|
|
export {parseDateString, formatDate};
|