Daniel Werner has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/64043


Change subject: added equals function for Time, and using it in DataValue now
......................................................................

added equals function for Time, and using it in DataValue now

Change-Id: If5e5990f6e32f69df145033311120e433b2dd36d
---
M DataValues/resources/time.js/src/time.Time.js
M DataValues/resources/time.js/tests/time.Time.tests.js
M DataValues/resources/values/TimeValue.js
3 files changed, 50 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues 
refs/changes/43/64043/1

diff --git a/DataValues/resources/time.js/src/time.Time.js 
b/DataValues/resources/time.js/src/time.Time.js
index 40d1d5e..c060bcf 100644
--- a/DataValues/resources/time.js/src/time.Time.js
+++ b/DataValues/resources/time.js/src/time.Time.js
@@ -181,6 +181,22 @@
                };
        };
 
+       /**
+        * Returns whether some given time is equal to this one.
+        *
+        * @param {*|time.Time} otherTime
+        * @returns boolean
+        */
+       Time.prototype.equals = function( otherTime ) {
+               if( !( otherTime instanceof Time ) ) {
+                       return false;
+               }
+
+               return this.isValid() && otherTime.isValid() // two invalid 
times are not equal
+                       && this.precision() === otherTime.precision()
+                       && this.iso8601() === otherTime.iso8601();
+       };
+
        function pad( number, digits ) {
                return ( 1e12 + Math.abs( number ) + '' ).slice( -digits );
        }
diff --git a/DataValues/resources/time.js/tests/time.Time.tests.js 
b/DataValues/resources/time.js/tests/time.Time.tests.js
index 22dfb7d..97e3cc0 100644
--- a/DataValues/resources/time.js/tests/time.Time.tests.js
+++ b/DataValues/resources/time.js/tests/time.Time.tests.js
@@ -55,4 +55,37 @@
                );
        }
 
+       QUnit.test( 'time.Time.equals()', function( assert ) {
+               $.each( validTimeDefinitions, function( name, definition ) {
+                       var time1 = new Time( definition ),
+                               time2 = new Time( definition );
+
+                       assert.ok(
+                               time1.equals( time2 ) && time2.equals( time1 ),
+                               'equal() works for time definition of "' + name 
+ '"'
+                       );
+
+               } );
+       } );
+
+       QUnit.test( 'Equality of Time objects constructed by object/string', 
function( assert ) {
+               var equalTimeObjects = {};
+               $.each( validTimeDefinitions, function( name, definition ) {
+                       equalTimeObjects[ name ] = {
+                               byObject: new Time( definition ),
+                               byString: new Time( name )
+                       };
+               } );
+               $.each( equalTimeObjects, function( name, equalTimes ) {
+                       var timeByObject = equalTimes.byObject,
+                               timeByString = equalTimes.byString;
+
+                       assert.ok(
+                               timeByObject.equals( timeByString ),
+                               'Time created from string "' + name + '" and 
time created from equivalent time ' +
+                                       'object definition are equal'
+                       );
+               } );
+       } );
+
 }( QUnit, jQuery, time ) );
diff --git a/DataValues/resources/values/TimeValue.js 
b/DataValues/resources/values/TimeValue.js
index 3436ee5..d96ecef 100644
--- a/DataValues/resources/values/TimeValue.js
+++ b/DataValues/resources/values/TimeValue.js
@@ -62,14 +62,7 @@
                        if ( !( value instanceof SELF ) ) {
                                return false;
                        }
-
-                       var ownTime = this.getValue(),
-                               otherTime = value.getValue();
-
-                       // no need to check for isValid() since constructor 
won't allow invalid Time values
-
-                       return ownTime.precision() === otherTime.precision()
-                               && ownTime.iso8601() === otherTime.iso8601();
+                       return this.getValue().equals( value.getValue() );
                },
 
                /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If5e5990f6e32f69df145033311120e433b2dd36d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <daniel.wer...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to