Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344743 )

Change subject: Use mw.now() instead of 'new Date' for relative measurement
......................................................................

Use mw.now() instead of 'new Date' for relative measurement

'new Date' is subject to clock trift etc.

mw.now() uses performance.now() when available, which will always
increase at a constant rate independent of the system clock.

Change-Id: Ib653103bf6116544f35c930fb33421f1bb362c7d
---
M resources/src/jquery/jquery.suggestions.js
M resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
M resources/src/startup.js
3 files changed, 7 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/43/344743/1

diff --git a/resources/src/jquery/jquery.suggestions.js 
b/resources/src/jquery/jquery.suggestions.js
index fdc8a26..75f1ba6 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 172cac2..2f90fe6 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 );
diff --git a/resources/src/startup.js b/resources/src/startup.js
index deb280a..5179ac0 100644
--- a/resources/src/startup.js
+++ b/resources/src/startup.js
@@ -15,7 +15,7 @@
                        navStart = perf && perf.timing && 
perf.timing.navigationStart;
                return navStart && typeof perf.now === 'function' ?
                        function () { return navStart + perf.now(); } :
-                       function () { return +new Date(); };
+                       function () { return Date.now(); };
        }() ),
        // eslint-disable-next-line no-unused-vars
        mediaWikiLoadStart = mwNow();

-- 
To view, visit https://gerrit.wikimedia.org/r/344743
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib653103bf6116544f35c930fb33421f1bb362c7d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to