X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/004e528060e42b45c8207e43892289b14f5aa2e5..5923d0fa912c73e3725e52c869d72793304ae44a:/apps/workbench/app/assets/javascripts/dates.js diff --git a/apps/workbench/app/assets/javascripts/dates.js b/apps/workbench/app/assets/javascripts/dates.js index 9e484ce15d..5e4b804a2d 100644 --- a/apps/workbench/app/assets/javascripts/dates.js +++ b/apps/workbench/app/assets/javascripts/dates.js @@ -1,11 +1,25 @@ +jQuery(function($){ $(document).on('ajax:complete arv:pane:loaded ready', function() { - console.log("woble!"); $('[data-utc-date]').each(function(i, elm) { - var re = /(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) UTC/; - var v = $(elm).attr('data-utc-date').match(re); + // Try matching the date using a couple of different formats. + var v = $(elm).attr('data-utc-date').match(/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) UTC/); + if (!v) { + v = $(elm).attr('data-utc-date').match(/(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z/); + } + if (v) { + // Create a new date object from the timestamp so the browser can + // render the date based on the locale/timezone. var ts = new Date(Date.UTC(v[1], v[2]-1, v[3], v[4], v[5], v[6])); - $(elm).text(ts.toLocaleTimeString() + " " + ts.toLocaleDateString()); + if ($(elm).attr('data-utc-date-opts') && $(elm).attr('data-utc-date-opts').match(/noseconds/)) { + $(elm).text((ts.getHours() > 12 ? (ts.getHours()-12) : ts.getHours()) + + ":" + (ts.getMinutes() < 10 ? '0' : '') + ts.getMinutes() + + (ts.getHours() >= 12 ? " PM " : " AM ") + + ts.toLocaleDateString()); + } else { + $(elm).text(ts.toLocaleTimeString() + " " + ts.toLocaleDateString()); + } } }); }); +});