diff options
author | Joey Hess <joey@gnu.kitenet.net> | 2009-04-23 13:39:42 -0400 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2009-04-23 13:39:42 -0400 |
commit | 2c74f09bb870c717669f273ba7d4aa1637dcccf1 (patch) | |
tree | e2d266db63a142b0701b190b2edf49220c9b28bc /underlays | |
parent | 86d6b40070023409882a5768a4db899e523bba71 (diff) |
relativedate: Deal with clock skew.
If the server has a clock running a bit ahead of the web browsing client,
relativedate could cause somewhat confusing displays like "3 seconds from now"
for just posted things.
As a hack, avoid displaying times in the future if they're less than a
small slip forward. I chose 30 minutes because both client and server could
be wrong in different directions, while it's still close enough that "just
now" is not horribly wrong.
Diffstat (limited to 'underlays')
-rw-r--r-- | underlays/javascript/relativedate.js | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/underlays/javascript/relativedate.js b/underlays/javascript/relativedate.js index 8e05d4065..5142332f1 100644 --- a/underlays/javascript/relativedate.js +++ b/underlays/javascript/relativedate.js @@ -45,6 +45,12 @@ function relativeDate(date) { var offset = date.getTime() - now.getTime(); var seconds = Math.round(Math.abs(offset) / 1000); + // hack to avoid reading just in the future if there is a minor + // amount of clock slip + if (offset >= 0 && seconds < 30 * timeUnits['minute']) { + return "just now"; + } + var ret = ""; var shown = 0; for (i = 0; i < timeUnitOrder.length; i++) { |