From: Timo Tijhof Date: Sat, 25 Mar 2017 03:37:23 +0000 (-0700) Subject: Ensure we use mw.now() instead of 'new Date' for relative measurement X-Git-Tag: 1.31.0-rc.0~3699^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=928cf05c57bcedac6c83e8c22be79793ad3ce814;p=lhc%2Fweb%2Fwiklou.git Ensure we use mw.now() instead of 'new Date' for relative measurement 'new Date' is subject to clock drift etc. mw.now() uses performance.now() when available, which will always increase at a constant rate independent of the system clock. Change-Id: Ib653103bf6116544f35c930fb33421f1bb362c7d --- diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index fdc8a266ad..75f1ba6e8e 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -96,7 +96,7 @@ */ // jscs:enable checkParamNames -( function ( $ ) { +( function ( $, mw ) { var hasOwn = Object.hasOwnProperty; @@ -178,7 +178,7 @@ context.data.prevText = val; // Try cache first if ( context.config.cache && hasOwn.call( cache, val ) ) { - if ( +new Date() - cache[ val ].timestamp < context.config.cacheMaxAge ) { + if ( mw.now() - cache[ val ].timestamp < context.config.cacheMaxAge ) { context.data.$textbox.suggestions( 'suggestions', cache[ val ].suggestions ); if ( typeof context.config.update.after === 'function' ) { context.config.update.after.call( context.data.$textbox, cache[ val ].metadata ); @@ -203,7 +203,7 @@ cache[ val ] = { suggestions: suggestions, metadata: metadata, - timestamp: +new Date() + timestamp: mw.now() }; } }, @@ -786,4 +786,4 @@ * @mixins jQuery.plugin.suggestions */ -}( jQuery ) ); +}( jQuery, mediaWiki ) ); diff --git a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js index 172cac2379..2f90fe6847 100644 --- a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js +++ b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js @@ -230,7 +230,7 @@ */ mw.Upload.BookletLayout.prototype.uploadFile = function () { var deferred = $.Deferred(), - startTime = new Date(), + startTime = mw.now(), layout = this, file = this.getFile(); @@ -265,7 +265,7 @@ deferred.reject( errorMessage ); } ); }, function ( progress ) { - var elapsedTime = new Date() - startTime, + var elapsedTime = mw.now() - startTime, estimatedTotalTime = ( 1 / progress ) * elapsedTime, estimatedRemainingTime = moment.duration( estimatedTotalTime - elapsedTime ); layout.emit( 'fileUploadProgress', progress, estimatedRemainingTime );