8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / app / assets / javascripts / dates.js
1 jQuery(function($){
2 $(document).on('ajax:complete arv:pane:loaded ready', function() {
3     $('[data-utc-date]').each(function(i, elm) {
4         // Try matching the date using a couple of different formats.
5         var v = $(elm).attr('data-utc-date').match(/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) UTC/);
6         if (!v) {
7             v = $(elm).attr('data-utc-date').match(/(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z/);
8         }
9
10         if (v) {
11             // Create a new date object from the timestamp so the browser can
12             // render the date based on the locale/timezone.
13             var ts = new Date(Date.UTC(v[1], v[2]-1, v[3], v[4], v[5], v[6]));
14             if ($(elm).attr('data-utc-date-opts') && $(elm).attr('data-utc-date-opts').match(/noseconds/)) {
15                 $(elm).text((ts.getHours() > 12 ? (ts.getHours()-12) : ts.getHours())
16                             + ":" + (ts.getMinutes() < 10 ? '0' : '') + ts.getMinutes()
17                             + (ts.getHours() >= 12 ? " PM " : " AM ")
18                             + ts.toLocaleDateString());
19             } else {
20                 $(elm).text(ts.toLocaleTimeString() + " " + ts.toLocaleDateString());
21             }
22         }
23     });
24 });
25 });