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

Side by Side Diff: appengine/swarming/ui/res/js/common.js

Issue 2832423003: Fix Swarming UI timezone bug (Closed)
Patch Set: Fix copy-pasta and use sk.human Created 3 years, 8 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 | « appengine/swarming/ui/res/imp/taskpage/task-page-data.html ('k') | 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 this.swarming = this.swarming || function() { 5 this.swarming = this.swarming || function() {
6 6
7 var swarming = {}; 7 var swarming = {};
8 8
9 // return the longest string in an array 9 // return the longest string in an array
10 swarming.longest = function(arr) { 10 swarming.longest = function(arr) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return sk.request("POST", url, body, auth_headers).then(function(response) { 65 return sk.request("POST", url, body, auth_headers).then(function(response) {
66 sk.errorMessage("Request sent. Response: "+response, 3000); 66 sk.errorMessage("Request sent. Response: "+response, 3000);
67 return response; 67 return response;
68 }).catch(function(reason) { 68 }).catch(function(reason) {
69 console.log("Request failed", reason); 69 console.log("Request failed", reason);
70 sk.errorMessage("Request failed. Reason: "+reason, 5000); 70 sk.errorMessage("Request failed. Reason: "+reason, 5000);
71 return Promise.reject(reason); 71 return Promise.reject(reason);
72 }); 72 });
73 } 73 }
74 74
75 // sanitizeAndHumanizeTime parses a date string or ms_since_epoch into a JS
76 // Date object, assuming UTC time. It also creates a human readable form in
77 // the obj under a key with a human_ prefix. E.g.
78 // swarming.sanitizeAndHumanizeTime(foo, "some_ts")
79 // parses the string/int at foo["some_ts"] such that foo["some_ts"] is now a
80 // Date object and foo["human_some_ts"] is the human formated version from
81 // sk.human.localeTime.
82 swarming.sanitizeAndHumanizeTime = function(obj, key) {
83 if (obj[key]) {
84 if (obj[key].endsWith && !obj[key].endsWith('Z')) {
85 // Timestamps from the server are missing the 'Z' that specifies Zulu
86 // (UTC) time. If that's not the case, add the Z. Otherwise, some
87 // browsers interpret this as local time, which throws off everything.
88 // TODO(kjlubick): Should the server output milliseconds since the
89 // epoch? That would be more consistent.
stephana 2017/04/24 13:27:14 +1 for outputting all times in ms since the epoch.
90 // See http://crbug.com/714599
91 obj[key] += 'Z';
92 }
93 obj[key] = new Date(obj[key]);
94 obj["human_"+key] = sk.human.localeTime(obj[key]);
95 }
96 }
97
75 return swarming; 98 return swarming;
76 }(); 99 }();
OLDNEW
« no previous file with comments | « appengine/swarming/ui/res/imp/taskpage/task-page-data.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698