From 9cf417b10ee85cccbf01e52840793cd2dc36fbf1 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 12 Jun 2013 16:26:45 +0200 Subject: [PATCH] Fixes issue with relative times and calculation of days in JS --- wcfsetup/install/files/js/WCF.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 3e50c118a4..ccf76c519f 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -2729,6 +2729,12 @@ WCF.Date.Util = { * Handles relative time designations. */ WCF.Date.Time = Class.extend({ + /** + * Date of current timestamp + * @var Date + */ + _date: 0, + /** * list of time elements * @var jQuery @@ -2777,8 +2783,8 @@ WCF.Date.Time = Class.extend({ * Refreshes relative datetime for each element. */ _refresh: function() { - var $date = new Date(); - this._timestamp = ($date.getTime() - $date.getMilliseconds()) / 1000; + this._date = new Date(); + this._timestamp = (this._date.getTime() - this._date.getMilliseconds()) / 1000; if (this._offset === null) { this._offset = this._timestamp - TIME_NOW; } @@ -2823,7 +2829,8 @@ WCF.Date.Time = Class.extend({ } // timestamp is less than 6 days ago else if (this._timestamp < ($timestamp + 518400)) { - var $days = Math.round((this._timestamp - $timestamp) / 86400); + var $midnight = new Date(this._date.getFullYear(), this._date.getMonth(), this._date.getDate()); + var $days = Math.ceil(($midnight / 1000 - $timestamp) / 86400); // get day of week var $dateObj = WCF.Date.Util.getTimezoneDate(($timestamp * 1000), $offset); -- 2.20.1