forked from GithubBackups/healthchecks
secsToText uses same algorithm as Python version. Position slider labels evenly.
This commit is contained in:
parent
c360dc5e53
commit
d456c37781
@ -1,19 +1,27 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
var secsToText = function(total) {
|
var MINUTE = {name: "minute", nsecs: 60};
|
||||||
total = Math.floor(total / 60);
|
var HOUR = {name: "hour", nsecs: MINUTE.nsecs * 60};
|
||||||
var m = total % 60; total = Math.floor(total / 60);
|
var DAY = {name: "day", nsecs: HOUR.nsecs * 24};
|
||||||
var h = total % 24; total = Math.floor(total / 24);
|
var WEEK = {name: "week", nsecs: DAY.nsecs * 7};
|
||||||
var d = total % 30 % 7;
|
var MONTH = {name: "month", nsecs: DAY.nsecs * 30};
|
||||||
var o = Math.floor(total / 30);
|
var UNITS = [MONTH, WEEK, DAY, HOUR, MINUTE];
|
||||||
var w = Math.floor(total % 30 / 7);
|
|
||||||
|
|
||||||
|
var secsToText = function(total) {
|
||||||
|
var remainingSeconds = Math.floor(total);
|
||||||
var result = "";
|
var result = "";
|
||||||
if (o) result += o + (o === 1 ? " month " : " months ");
|
for (var i=0, unit; unit=UNITS[i]; i++) {
|
||||||
if (w) result += w + (w === 1 ? " week " : " weeks ");
|
var count = Math.floor(remainingSeconds / unit.nsecs);
|
||||||
if (d) result += d + (d === 1 ? " day " : " days ");
|
remainingSeconds = remainingSeconds % unit.nsecs;
|
||||||
if (h) result += h + (h === 1 ? " hour " : " hours ");
|
|
||||||
if (m) result += m + (m === 1 ? " minute " : " minutes ");
|
if (count == 1) {
|
||||||
|
result += "1 " + unit.name + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 1) {
|
||||||
|
result += count + " " + unit.name + "s ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -24,15 +32,15 @@ $(function () {
|
|||||||
connect: "lower",
|
connect: "lower",
|
||||||
range: {
|
range: {
|
||||||
'min': [60, 60],
|
'min': [60, 60],
|
||||||
'30%': [3600, 3600],
|
'33%': [3600, 3600],
|
||||||
'50%': [86400, 86400],
|
'66%': [86400, 86400],
|
||||||
'80%': [604800, 604800],
|
'83%': [604800, 604800],
|
||||||
'max': 2592000,
|
'max': 2592000,
|
||||||
},
|
},
|
||||||
pips: {
|
pips: {
|
||||||
mode: 'values',
|
mode: 'values',
|
||||||
values: [60, 1800, 3600, 43200, 86400, 604800, 2592000],
|
values: [60, 1800, 3600, 43200, 86400, 604800, 2592000],
|
||||||
density: 5,
|
density: 4,
|
||||||
format: {
|
format: {
|
||||||
to: secsToText,
|
to: secsToText,
|
||||||
from: function() {}
|
from: function() {}
|
||||||
@ -53,9 +61,9 @@ $(function () {
|
|||||||
connect: "lower",
|
connect: "lower",
|
||||||
range: {
|
range: {
|
||||||
'min': [60, 60],
|
'min': [60, 60],
|
||||||
'30%': [3600, 3600],
|
'33%': [3600, 3600],
|
||||||
'50%': [86400, 86400],
|
'66%': [86400, 86400],
|
||||||
'80%': [604800, 604800],
|
'83%': [604800, 604800],
|
||||||
'max': 2592000,
|
'max': 2592000,
|
||||||
},
|
},
|
||||||
pips: {
|
pips: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user