Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: milo/appengine/frontend/static/common/js/time.js

Issue 2691003002: Display "(local time)" label after start/end time of the build (Closed)
Patch Set: Addressed comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // A Series of time based utilites for Milo. 5 // A Series of time based utilites for Milo.
6 6
7 7
8 (function(window) { 8 (function(window) {
9 'use strict'; 9 'use strict';
10 10
11 var milo = window.milo || {}; 11 var milo = window.milo || {};
12 12
13 /** 13 /**
14 * Given a Date, return a time string in the user's local timezone. 14 * Given a Date, return a time string in the user's local timezone.
15 */ 15 */
16 milo.formatDate = function(t) { 16 milo.formatDate = function(t) {
17 if (!t || t.toString() == "Invalid Date") { 17 if (!t || t.toString() == "Invalid Date") {
18 return null; 18 return null;
19 } 19 }
20 var shortDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 20 var shortDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
21 var offset = -(new Date()).getTimezoneOffset(); 21
22 var offsetHr = Math.abs(Math.round(offset / 60)); 22 var offset = -t.getTimezoneOffset();
23 var offsetMin = Math.abs(Math.abs(offset) - (offsetHr * 60)); 23 var offsetHr = Math.floor(Math.abs(offset) / 60);
24 var offsetMin = Math.abs(offset) % 60;
25 var offsetSign = '';
hinoka 2017/02/28 18:10:41 Don't need this anymore
Sergiy Byelozyorov 2017/03/01 08:35:04 Done.
24 if (offsetHr < 10) { 26 if (offsetHr < 10) {
25 offsetHr = '0' + offsetHr; 27 offsetHr = '0' + offsetHr;
26 } 28 }
27 if (offsetMin < 10) { 29 if (offsetMin < 10) {
28 offsetMin = '0' + offsetMin; 30 offsetMin = '0' + offsetMin;
29 } 31 }
32 if (offset < 0) {
hinoka 2017/02/28 18:10:41 Or this
Sergiy Byelozyorov 2017/03/01 08:35:04 Done.
33 offsetSign = '-';
34 } else if (offset > 0) {
35 offsetSign = '+';
36 }
30 37
31 var month = (t.getMonth() + 1); 38 var month = (t.getMonth() + 1);
32 if (month < 10) { 39 if (month < 10) {
33 month = '0' + month; 40 month = '0' + month;
34 } 41 }
35 var date = t.getDate(); 42 var date = t.getDate();
36 if (date < 10) { 43 if (date < 10) {
37 date = '0' + date; 44 date = '0' + date;
38 } 45 }
39 var s = shortDayNames[t.getDay()] + ', '; 46 var s = shortDayNames[t.getDay()] + ', ';
40 s += t.getFullYear() + '-' + month + '-' + date + ' '; 47 s += t.getFullYear() + '-' + month + '-' + date + ' ';
41 s += t.toLocaleTimeString(); 48 s += t.toLocaleTimeString() + ' (local time)';
42 49
43 return s; 50 return s;
44 }; 51 };
45 52
46 milo.makeTimesLocal = function() { 53 milo.makeTimesLocal = function() {
47 var timeSpans = document.getElementsByClassName('local-time'); 54 var timeSpans = document.getElementsByClassName('local-time');
48 for (var i = 0; i < timeSpans.length; i++) { 55 for (var i = 0; i < timeSpans.length; i++) {
49 var span = timeSpans[i]; 56 var span = timeSpans[i];
50 try { 57 try {
51 var oldTimestamp = span.innerText; 58 var oldTimestamp = span.innerText;
52 var timestamp = span.getAttribute('data-timestamp'); 59 var timestamp = span.getAttribute('data-timestamp');
53 var date = new Date(parseInt(timestamp, 10)); 60 var date = new Date(parseInt(timestamp, 10));
54 var newTimestamp = milo.formatDate(date); 61 var newTimestamp = milo.formatDate(date);
55 if (newTimestamp != null) { 62 if (newTimestamp != null) {
56 span.innerText = newTimestamp; 63 span.innerText = newTimestamp;
57 span.setAttribute("title", oldTimestamp) 64 span.setAttribute("title", oldTimestamp)
58 } 65 }
59 } 66 }
60 catch (e) { 67 catch (e) {
61 console.error('could not convert time of span', span, 'to local:', e) 68 console.error('could not convert time of span', span, 'to local:', e)
62 } 69 }
63 } 70 }
64 }; 71 };
65 72
66 window.milo = milo; 73 window.milo = milo;
67 74
68 }(window)); 75 }(window));
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698