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

Unified Diff: appengine/swarming/elements/res/js/common.js

Issue 2227803002: Mirror filters and sort preferences to url-params (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@use-dimensions
Patch Set: Tweak docs Created 4 years, 4 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/elements/res/imp/common/url-param.html ('k') | appengine/swarming/handlers_endpoints.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/elements/res/js/common.js
diff --git a/appengine/swarming/elements/res/js/common.js b/appengine/swarming/elements/res/js/common.js
index 89038897419b998b30aa211d6cc495cf3f8d7000..e0da135d8873721d1ae719b6e0d25c92ba5515c0 100644
--- a/appengine/swarming/elements/res/js/common.js
+++ b/appengine/swarming/elements/res/js/common.js
@@ -50,66 +50,5 @@ this.swarming = this.swarming || function() {
return a.localeCompare(b);
};
-
- var TIME_DELTAS = [
- { units: "w", delta: 7*24*60*60 },
- { units: "d", delta: 24*60*60 },
- { units: "h", delta: 60*60 },
- { units: "m", delta: 60 },
- { units: "s", delta: 1 },
- ];
-
- /**
- * Returns the difference between the specified time and 's' as a string in a
- * human friendly format.
- * If left unspecified, "now" defaults to Date.now()
- * If 's' is a number it is assumed to contain the time in milliseconds
- * otherwise it is assumed to contain a time string.
- *
- * For example, a difference of 123 seconds between 's' and the current time
- * would return "2m".
- */
- swarming.diffDate = function(s, now) {
- var ms = (typeof(s) == "number") ? s : Date.parse(s);
- now = now || Date.now();
- var diff = (ms - now)/1000;
- if (diff < 0) {
- diff = -1.0 * diff;
- }
- return humanize(diff, TIME_DELTAS);
- };
-
- swarming.KB = 1024;
- swarming.MB = swarming.KB * 1024;
- swarming.GB = swarming.MB * 1024
-
- var BYTES_DELTAS = [
- { units: " TB", delta: 1024*swarming.GB},
- { units: " GB", delta: swarming.GB},
- { units: " MB", delta: swarming.MB},
- { units: " KB", delta: swarming.KB},
- { units: " B", delta: 1},
- ];
-
- swarming.humanBytes = function(b, unit) {
- if (Number.isInteger(unit)) {
- b = b * unit;
- }
- return humanize(b, BYTES_DELTAS);
- }
-
- function humanize(n, deltas) {
- for (var i=0; i<deltas.length-1; i++) {
- // If n would round to '60s', return '1m' instead.
- var nextDeltaRounded =
- Math.round(n/deltas[i+1].delta)*deltas[i+1].delta;
- if (nextDeltaRounded/deltas[i].delta >= 1) {
- return Math.round(n/deltas[i].delta)+deltas[i].units;
- }
- }
- var i = DELTAS.length-1;
- return Math.round(n/DELTAS[i].delta)+DELTAS[i].units;
- }
-
return swarming;
}();
« no previous file with comments | « appengine/swarming/elements/res/imp/common/url-param.html ('k') | appengine/swarming/handlers_endpoints.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698