]> sipb.mit.edu Git - ikiwiki.git/commitdiff
relativedate: Deal with clock skew.
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 23 Apr 2009 17:39:42 +0000 (13:39 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 23 Apr 2009 17:39:42 +0000 (13:39 -0400)
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.

debian/changelog
underlays/javascript/relativedate.js

index ba3042af00878e2f2ff1d9653a40a6f5127f55cb..fbfed0007437e1da1054c1c2a56c38380ad9b5e1 100644 (file)
@@ -7,6 +7,7 @@ ikiwiki (3.11) UNRELEASED; urgency=low
     allowing the admin to see it during wiki setup.
     Closes: #520015
   * websetup: If setup fails, restore old setup file.
     allowing the admin to see it during wiki setup.
     Closes: #520015
   * websetup: If setup fails, restore old setup file.
+  * relativedate: Deal with clock skew.
 
  -- Joey Hess <joeyh@debian.org>  Tue, 21 Apr 2009 21:41:38 -0400
 
 
  -- Joey Hess <joeyh@debian.org>  Tue, 21 Apr 2009 21:41:38 -0400
 
index 8e05d4065521f473c776ae37e3eed2db42c334b6..5142332f1132b833fe119764a5c0055519551790 100644 (file)
@@ -45,6 +45,12 @@ function relativeDate(date) {
        var offset = date.getTime() - now.getTime();
        var seconds = Math.round(Math.abs(offset) / 1000);
 
        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++) {
        var ret = "";
        var shown = 0;
        for (i = 0; i < timeUnitOrder.length; i++) {