jenkins-bot has submitted this change and it was merged.
Change subject: [time.js] added time.Time.minPrecision and tests
......................................................................
[time.js] added time.Time.minPrecision and tests
Change-Id: Ic6184fc141032c7601b8ff023ada53a64c7e6538
---
M DataValues/DataValues.tests.qunit.php
M DataValues/resources/time.js/src/time.Time.js
M DataValues/resources/time.js/tests/time.Time.knowsPrecision.tests.js
A DataValues/resources/time.js/tests/time.Time.minPrecision.tests.js
4 files changed, 69 insertions(+), 3 deletions(-)
Approvals:
Henning Snater: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataValues/DataValues.tests.qunit.php
b/DataValues/DataValues.tests.qunit.php
index 3e8a0ab..758fe2a 100644
--- a/DataValues/DataValues.tests.qunit.php
+++ b/DataValues/DataValues.tests.qunit.php
@@ -83,6 +83,7 @@
'time.js.tests' => array(
'scripts' => array(
'resources/time.js/tests/time.Time.knowsPrecision.tests.js',
+
'resources/time.js/tests/time.Time.minPrecision.tests.js',
'resources/time.js/tests/time.Time.maxPrecision.tests.js',
),
'dependencies' => array(
diff --git a/DataValues/resources/time.js/src/time.Time.js
b/DataValues/resources/time.js/src/time.Time.js
index ca9d25d..f6839d8 100644
--- a/DataValues/resources/time.js/src/time.Time.js
+++ b/DataValues/resources/time.js/src/time.Time.js
@@ -158,7 +158,7 @@
* TODO: throw an error if invalid Time, don't support invalid
data objects and deprecate
* this function then.
*
- * @returns {boolean}
+ * @return {boolean}
*/
this.isValid = function() {
return this.year() !== null;
@@ -230,7 +230,7 @@
* Returns whether a given number can be interpreted as a Time's
precision.
*
* @param {number} precision
- * @returns {boolean}
+ * @return {boolean}
*/
Time.knowsPrecision = function( precision ) {
var precisionKey;
@@ -243,9 +243,18 @@
};
/**
+ * Returns the lowest possible precision from the time.Time.PRECISION
enum.
+ *
+ * @return {Number}
+ */
+ Time.minPrecision = function() {
+ return Time.PRECISION.GY;
+ };
+
+ /**
* Returns the highest possible precision from the time.Time.PRECISION
enum.
*
- * @returns {Number}
+ * @return {Number}
*/
Time.maxPrecision = function() {
return Time.PRECISION.SECOND;
diff --git
a/DataValues/resources/time.js/tests/time.Time.knowsPrecision.tests.js
b/DataValues/resources/time.js/tests/time.Time.knowsPrecision.tests.js
index 861add6..a713c11 100644
--- a/DataValues/resources/time.js/tests/time.Time.knowsPrecision.tests.js
+++ b/DataValues/resources/time.js/tests/time.Time.knowsPrecision.tests.js
@@ -28,6 +28,10 @@
'Precision above highest precision is an unknown
precision'
);
assert.ok(
+ !Time.knowsPrecision( Time.minPrecision() - 1 ),
+ 'Precision below lowest precision is an unknown
precision'
+ );
+ assert.ok(
!Time.knowsPrecision( 'foo' ),
'Random string is not a known precision'
);
diff --git a/DataValues/resources/time.js/tests/time.Time.minPrecision.tests.js
b/DataValues/resources/time.js/tests/time.Time.minPrecision.tests.js
new file mode 100644
index 0000000..c6eec4a
--- /dev/null
+++ b/DataValues/resources/time.js/tests/time.Time.minPrecision.tests.js
@@ -0,0 +1,52 @@
+/**
+ * @since 0.1
+ * @file
+ * @ingroup Time.js
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner
+ */
+( function( QUnit, jQuery, Time ) {
+ 'use strict';
+
+ QUnit.module( 'Time.js: time.Time.minPrecision' );
+
+ QUnit.test( 'time.Time.minPrecision() return value', function( assert )
{
+ var minPrecision = Time.minPrecision();
+
+ assert.ok(
+ typeof minPrecision === 'number',
+ 'returns a number'
+ );
+
+ assert.ok(
+ !isNaN( minPrecision ),
+ 'return value is not NaN'
+ );
+ } );
+
+ QUnit.test( 'minPrecision accuracy', function( assert ) {
+ var precisionKey, precision,
+ minDetermined = Number.POSITIVE_INFINITY;
+
+ for( precisionKey in Time.PRECISION ) {
+ precision = Time.PRECISION[ precisionKey ];
+
+ assert.ok(
+ precision >= Time.minPrecision(),
+ 'precision "' + precisionKey + '" greater or
equal time.Time.minPrecision()'
+ );
+
+ if( precision < minDetermined ) {
+ minDetermined = precision;
+ }
+ }
+
+ assert.strictEqual(
+ Time.minPrecision(),
+ minDetermined,
+ 'time.Time.minPrecision() returns lowest number within
the precision enum'
+ );
+ } );
+
+}( QUnit, jQuery, time.Time ) );
--
To view, visit https://gerrit.wikimedia.org/r/63989
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic6184fc141032c7601b8ff023ada53a64c7e6538
Gerrit-PatchSet: 7
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