unify date parsing and fall back to raw value if it failed

This commit is contained in:
j 2018-08-05 19:07:31 +01:00
parent 72358a7bce
commit 4e4d64febc
3 changed files with 24 additions and 18 deletions

View file

@ -412,11 +412,8 @@ pandora.ui.documentInfoView = function(data) {
function formatValue(key, value) { function formatValue(key, value) {
var ret; var ret;
if (key == 'date') { if (key == 'date' && (!value || value.split('-').length < 4)) {
ret = value ? Ox.formatDate(value, ret = pandora.formatDate(value);
['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length],
true
) : '';
} else if (nameKeys.indexOf(key) > -1) { } else if (nameKeys.indexOf(key) > -1) {
ret = formatLink(value.split(', '), key); ret = formatLink(value.split(', '), key);
} else if (listKeys.indexOf(key) > -1) { } else if (listKeys.indexOf(key) > -1) {

View file

@ -594,19 +594,7 @@ pandora.ui.infoView = function(data) {
function formatValue(key, value) { function formatValue(key, value) {
var ret; var ret;
if (key == 'date' && (!value || value.split('-').length < 4)) { if (key == 'date' && (!value || value.split('-').length < 4)) {
if (!value) { ret = pandora.formatDate(value);
ret = ''
} else if (Ox.contains(value, ':') && value.split('-').length == 3) {
ret = Ox.formatDate(value,
['', '', '%B %e, %Y %H:%M', '%B %e, %Y %H:%M:%S'][value.split(':').length],
false
);
} else {
ret = Ox.formatDate(value,
['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length],
true
);
}
} else if (listKeys.indexOf(key) > -1) { } else if (listKeys.indexOf(key) > -1) {
ret = value.split(', '); ret = value.split(', ');
} else { } else {

View file

@ -1115,6 +1115,27 @@ pandora.formatDocumentKey = function(key, data, size) {
return value; return value;
} }
pandora.formatDate = function(value) {
var ret;
if (!value) {
ret = ''
} else if (Ox.contains(value, ':') && value.split('-').length == 3) {
ret = Ox.formatDate(value,
['', '', '%B %e, %Y %H:%M', '%B %e, %Y %H:%M:%S'][value.split(':').length],
false
);
} else {
ret = Ox.formatDate(value,
['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length],
true
);
}
if (ret.trim() == 'NaN') {
ret = value;
}
return ret;
}
pandora.getAllItemsTitle = function(section) { pandora.getAllItemsTitle = function(section) {
section = section || pandora.user.ui.section; section = section || pandora.user.ui.section;
return { return {