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