From 4e4d64febc02fbf199f759999f0362e7abcc6d51 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 5 Aug 2018 19:07:31 +0100 Subject: [PATCH] unify date parsing and fall back to raw value if it failed --- static/js/documentInfoView.js | 7 ++----- static/js/infoView.padma.js | 14 +------------- static/js/utils.js | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/static/js/documentInfoView.js b/static/js/documentInfoView.js index 99da3df5e..9d6c10101 100644 --- a/static/js/documentInfoView.js +++ b/static/js/documentInfoView.js @@ -412,11 +412,8 @@ pandora.ui.documentInfoView = function(data) { function formatValue(key, value) { var ret; - if (key == 'date') { - ret = value ? Ox.formatDate(value, - ['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length], - true - ) : ''; + if (key == 'date' && (!value || value.split('-').length < 4)) { + ret = pandora.formatDate(value); } else if (nameKeys.indexOf(key) > -1) { ret = formatLink(value.split(', '), key); } else if (listKeys.indexOf(key) > -1) { diff --git a/static/js/infoView.padma.js b/static/js/infoView.padma.js index 7a88f66b8..3bc49b35b 100644 --- a/static/js/infoView.padma.js +++ b/static/js/infoView.padma.js @@ -594,19 +594,7 @@ pandora.ui.infoView = function(data) { function formatValue(key, value) { var ret; if (key == 'date' && (!value || value.split('-').length < 4)) { - 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 - ); - } + ret = pandora.formatDate(value); } else if (listKeys.indexOf(key) > -1) { ret = value.split(', '); } else { diff --git a/static/js/utils.js b/static/js/utils.js index 226128833..097d7e4fe 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1115,6 +1115,27 @@ pandora.formatDocumentKey = function(key, data, size) { 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) { section = section || pandora.user.ui.section; return {