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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/ui/res/js/common.js
diff --git a/appengine/swarming/ui/res/js/common.js b/appengine/swarming/ui/res/js/common.js
index 0f0f30800492318103a8c8306835bce636ac7e56..abe8c6b10fdffc93483696d29837d7fb05a2376b 100644
--- a/appengine/swarming/ui/res/js/common.js
+++ b/appengine/swarming/ui/res/js/common.js
@@ -72,5 +72,28 @@ this.swarming = this.swarming || function() {
});
}
+ // sanitizeAndHumanizeTime parses a date string or ms_since_epoch into a JS
+ // Date object, assuming UTC time. It also creates a human readable form in
+ // the obj under a key with a human_ prefix. E.g.
+ // swarming.sanitizeAndHumanizeTime(foo, "some_ts")
+ // parses the string/int at foo["some_ts"] such that foo["some_ts"] is now a
+ // Date object and foo["human_some_ts"] is the human formated version from
+ // sk.human.localeTime.
+ swarming.sanitizeAndHumanizeTime = function(obj, key) {
+ if (obj[key]) {
+ if (obj[key].endsWith && !obj[key].endsWith('Z')) {
+ // Timestamps from the server are missing the 'Z' that specifies Zulu
+ // (UTC) time. If that's not the case, add the Z. Otherwise, some
+ // browsers interpret this as local time, which throws off everything.
+ // TODO(kjlubick): Should the server output milliseconds since the
+ // epoch? That would be more consistent.
stephana 2017/04/24 13:27:14 +1 for outputting all times in ms since the epoch.
+ // See http://crbug.com/714599
+ obj[key] += 'Z';
+ }
+ obj[key] = new Date(obj[key]);
+ obj["human_"+key] = sk.human.localeTime(obj[key]);
+ }
+ }
+
return swarming;
}();
« 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