Chromium Code Reviews| 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; |
| }(); |