aboutsummaryrefslogtreecommitdiff
path: root/underlays/javascript
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-05-27 23:57:00 -0400
committerJoey Hess <joey@kitenet.net>2010-05-27 23:57:00 -0400
commitc5b3ea0dd418dc1f9bb313a2e9be9d3a1b5c379e (patch)
tree1d06a409b2f42612a807048cdfa64eb98f70edff /underlays/javascript
parent3a868b6e7a53b8d6830cc0e51c967d3fb1045f81 (diff)
downloadikiwiki-c5b3ea0dd418dc1f9bb313a2e9be9d3a1b5c379e.tar
ikiwiki-c5b3ea0dd418dc1f9bb313a2e9be9d3a1b5c379e.tar.gz
avoid insane use of javascript "array"
Diffstat (limited to 'underlays/javascript')
-rw-r--r--underlays/javascript/ikiwiki/relativedate.js27
1 files changed, 13 insertions, 14 deletions
diff --git a/underlays/javascript/ikiwiki/relativedate.js b/underlays/javascript/ikiwiki/relativedate.js
index 5142332f1..2a270d627 100644
--- a/underlays/javascript/ikiwiki/relativedate.js
+++ b/underlays/javascript/ikiwiki/relativedate.js
@@ -32,13 +32,13 @@ function showDates() {
setTimeout(showDates,30000); // keep updating every 30s
}
-var timeUnits = new Array;
-timeUnits['minute'] = 60;
-timeUnits['hour'] = timeUnits['minute'] * 60;
-timeUnits['day'] = timeUnits['hour'] * 24;
-timeUnits['month'] = timeUnits['day'] * 30;
-timeUnits['year'] = timeUnits['day'] * 364;
-var timeUnitOrder = ['year', 'month', 'day', 'hour', 'minute'];
+var timeUnits = [
+ { unit: 'year', seconds: 60 * 60 * 24 * 364 },
+ { unit: 'month', seconds: 60 * 60 * 24 * 30 },
+ { unit: 'day', seconds: 60 * 60 * 24 },
+ { unit: 'hour', seconds: 60 * 60 },
+ { unit: 'minute', seconds: 60 },
+];
function relativeDate(date) {
var now = new Date();
@@ -47,20 +47,19 @@ function relativeDate(date) {
// hack to avoid reading just in the future if there is a minor
// amount of clock slip
- if (offset >= 0 && seconds < 30 * timeUnits['minute']) {
+ if (offset >= 0 && seconds < 30 * 60 * 60) {
return "just now";
}
var ret = "";
var shown = 0;
- for (i = 0; i < timeUnitOrder.length; i++) {
- var unit = timeUnitOrder[i];
- if (seconds >= timeUnits[unit]) {
- var num = Math.floor(seconds / timeUnits[unit]);
- seconds -= num * timeUnits[unit];
+ for (i = 0; i < timeUnits.length; i++) {
+ if (seconds >= timeUnits[i].seconds) {
+ var num = Math.floor(seconds / timeUnits[i].seconds);
+ seconds -= num * timeUnits[i].seconds;
if (ret)
ret += "and ";
- ret += num + " " + unit + (num > 1 ? "s" : "") + " ";
+ ret += num + " " + timeUnits[i].unit + (num > 1 ? "s" : "") + " ";
if (++shown == 2)
break;