jenkins-bot has submitted this change and it was merged.

Change subject: Testing UtilitiesTime and removing unused methods
......................................................................


Testing UtilitiesTime and removing unused methods

Change-Id: Ia6a819fb8eae0baefefce6c586d1c91ec121a838
Phabricator: http://fab.wmflabs.org/T451
---
M UploadWizardHooks.php
M resources/mw.UtilitiesTime.js
A tests/qunit/mw.UtilitiesTime.test.js
3 files changed, 69 insertions(+), 77 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index 97cae53..009c5b9 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -662,6 +662,7 @@
                                'tests/qunit/mw.UploadWizard.test.js',
                                
'tests/qunit/mw.UploadWizardLicenseInput.test.js',
                                'tests/qunit/mw.FlickrChecker.test.js',
+                               'tests/qunit/mw.UtilitiesTime.test.js',
                        ),
                        'dependencies' => array(
                                'ext.uploadWizard',
diff --git a/resources/mw.UtilitiesTime.js b/resources/mw.UtilitiesTime.js
index 03ab19c..e1de106 100644
--- a/resources/mw.UtilitiesTime.js
+++ b/resources/mw.UtilitiesTime.js
@@ -1,95 +1,46 @@
-/**
- * dependencies: [ mw ]
+/*
+ * This file is part of the MediaWiki extension UploadWizard.
+ *
+ * UploadWizard is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * UploadWizard is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with UploadWizard.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 ( function( mw ) {
-
        /**
-        * Given a float number of seconds, returns npt format response. ( 
ignore
-        * days for now )
-        *
-        * @param {Float}
-        *            sec Seconds
-        * @param {Boolean}
-        *            show_ms If milliseconds should be displayed.
-        * @return {Float} String npt format
+        * @class mw.UtilitiesTime
+        * @singleton
         */
-       mw.seconds2npt = function( sec, showMs ) {
-               if ( isNaN( sec ) ) {
-                       sec = 0;
-               }
-
-               var tm = mw.seconds2Measurements( sec ),
-                       hoursStr = '';
-
-               // Round the number of seconds to the required number of 
significant
-               // digits
-               if ( showMs ) {
-                       tm.seconds = Math.round( tm.seconds * 1000 ) / 1000;
-               } else {
-                       tm.seconds = Math.round( tm.seconds );
-               }
-               if ( tm.seconds < 10 ) {
-                       tm.seconds = '0' +      tm.seconds;
-               }
-               if ( tm.hours > 0 ) {
-                       if ( tm.minutes < 10 ) {
-                               tm.minutes = '0' + tm.minutes;
-                       }
-                       hoursStr = tm.hours + ':';
-               }
-               return hoursStr + tm.minutes + ':' + tm.seconds;
-       };
 
        /**
-        * Given seconds return array with 'days', 'hours', 'min', 'seconds'
-        *
-        * @param {float}
-        *            sec Seconds to be converted into time measurements
+        * Convert number into an object representing an amount of time.
+        * @param {number} sec Seconds to be converted into time measurements
+        * @return {Object}
+        * @return {number} return.days
+        * @return {number} return.hours
+        * @return {number} return.minutes
+        * @return {number} return.seconds
         */
        mw.seconds2Measurements = function ( sec ) {
                var tm = {};
                tm.days = Math.floor( sec / ( 3600 * 24 ) );
-               tm.hours = Math.floor( sec / 3600 );
+               tm.hours = Math.floor( ( sec / 3600 ) % 24 );
                tm.minutes = Math.floor( ( sec / 60 ) % 60 );
                tm.seconds = sec % 60;
                return tm;
        };
 
        /**
-        * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds
-        *
-        * @param {String}
-        *            npt_str NPT time string
-        * @return {Float} Number of seconds
+        * @class mw
+        * @mixins mw.UtilitiesTime.seconds2Measurements
         */
-       mw.npt2seconds = function ( nptStr ) {
-               var hour, min, sec, times;
-
-               if ( !nptStr ) {
-                       return undefined;
-               }
-               // Strip {npt:}01:02:20 or 32{s} from time if present
-               nptStr = nptStr.replace( /npt:|s/g, '' );
-
-               hour = 0;
-               min = 0;
-               sec = 0;
-               times = nptStr.split( ':' );
-
-               if ( times.length === 3 ) {
-                       sec = times[2];
-                       min = times[1];
-                       hour = times[0];
-               } else if ( times.length === 2 ) {
-                       sec = times[1];
-                       min = times[0];
-               } else {
-                       sec = times[0];
-               }
-               // Sometimes a comma is used instead of period for ms
-               sec = sec.replace( /,\s?/, '.' );
-               // Return seconds float
-               return parseInt( hour * 3600, 10 ) + parseInt( min * 60, 10 ) + 
parseFloat( sec );
-       };
-
 }( mediaWiki ) );
diff --git a/tests/qunit/mw.UtilitiesTime.test.js 
b/tests/qunit/mw.UtilitiesTime.test.js
new file mode 100644
index 0000000..90dc4ae
--- /dev/null
+++ b/tests/qunit/mw.UtilitiesTime.test.js
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the MediaWiki extension UploadWizard.
+ *
+ * UploadWizard is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * UploadWizard is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with UploadWizard.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+( function ( mw ) {
+    QUnit.module( 'mw.UtilitiesTime', QUnit.newMwEnvironment() );
+
+    QUnit.test( 'Basic maths testing', 3, function ( assert ) {
+       assert.deepEqual(
+               mw.seconds2Measurements( 1500 ),
+               { days: 0, hours: 0, minutes: 25, seconds: 0 },
+               'Basic time conversion test, minutes only'
+       );
+
+       assert.deepEqual(
+               mw.seconds2Measurements( 1893 ),
+               { days: 0, hours: 0, minutes: 31, seconds: 33 },
+               'Basic time conversion test, minutes and seconds'
+       );
+
+       assert.deepEqual(
+               mw.seconds2Measurements( 159291 ),
+               { days: 1, hours: 20, minutes: 14, seconds: 51 },
+               'Basic time conversion test, bigger number, all units'
+       );
+    } );
+}( mediaWiki ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia6a819fb8eae0baefefce6c586d1c91ec121a838
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to