jenkins-bot has submitted this change and it was merged.
Change subject: [time.js] added equals function for Time, and using it in
DataValue now
......................................................................
[time.js] 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(-)
Approvals:
Henning Snater: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataValues/resources/time.js/src/time.Time.js
b/DataValues/resources/time.js/src/time.Time.js
index 2fcfed6..c1ee87d 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
+ * @return 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 cd3dbeb..1cc098a 100644
--- a/DataValues/resources/time.js/tests/time.Time.tests.js
+++ b/DataValues/resources/time.js/tests/time.Time.tests.js
@@ -56,4 +56,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: merged
Gerrit-Change-Id: If5e5990f6e32f69df145033311120e433b2dd36d
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits