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

Change subject: Simplify TimeValueComparer switch a lot
......................................................................


Simplify TimeValueComparer switch a lot

Change-Id: Ibad8370656378dbf577b1530a99391f0e5a22e25
---
M includes/CrossCheck/Comparer/TimeValueComparer.php
M tests/phpunit/CrossCheck/Comparer/TimeValueComparerTest.php
2 files changed, 44 insertions(+), 15 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/CrossCheck/Comparer/TimeValueComparer.php 
b/includes/CrossCheck/Comparer/TimeValueComparer.php
index ea821a4..2ea130c 100644
--- a/includes/CrossCheck/Comparer/TimeValueComparer.php
+++ b/includes/CrossCheck/Comparer/TimeValueComparer.php
@@ -78,9 +78,11 @@
                $result = true;
 
                switch ( $precision ) {
+                       case TimeValue::PRECISION_SECOND:
+                               $result = $result && $diff->s === 0;
+                               // Fall through with no break/return. This is 
critical for this algorithm.
                        case TimeValue::PRECISION_MINUTE:
                                $result = $result && $diff->i === 0;
-                               // Fall through with no break/return. This is 
critical for this algorithm.
                        case TimeValue::PRECISION_HOUR:
                                $result = $result && $diff->h === 0;
                        case TimeValue::PRECISION_DAY:
@@ -88,31 +90,28 @@
                        case TimeValue::PRECISION_MONTH:
                                $result = $result && $diff->m === 0;
                        case TimeValue::PRECISION_YEAR:
-                               $result = $result && $diff->y === 0;
+                               return $result && $diff->y === 0;
                        case TimeValue::PRECISION_YEAR10:
-                               $result = $result && $diff->y < 10;
+                               return $diff->y < 10;
                        case TimeValue::PRECISION_YEAR100:
-                               $result = $result && $diff->y < 100;
+                               return $diff->y < 100;
                        case TimeValue::PRECISION_YEAR1K:
-                               $result = $result && $diff->y < 1000;
+                               return $diff->y < 1000;
                        case TimeValue::PRECISION_YEAR10K:
-                               $result = $result && $diff->y < 10000;
+                               return $diff->y < 10000;
                        case TimeValue::PRECISION_YEAR100K:
-                               $result = $result && $diff->y < 100000;
+                               return $diff->y < 100000;
                        case TimeValue::PRECISION_YEAR1M:
-                               $result = $result && $diff->y < 1000000;
+                               return $diff->y < 1000000;
                        case TimeValue::PRECISION_YEAR10M:
-                               $result = $result && $diff->y < 10000000;
+                               return $diff->y < 10000000;
                        case TimeValue::PRECISION_YEAR100M:
-                               $result = $result && $diff->y < 100000000;
+                               return $diff->y < 100000000;
                        case TimeValue::PRECISION_YEAR1G:
-                               $result = $result && $diff->y < 1000000000;
-                               break;
+                               return $diff->y < 1000000000;
                        default:
-                               $result = false;
+                               return false;
                }
-
-               return $result;
        }
 
        /**
diff --git a/tests/phpunit/CrossCheck/Comparer/TimeValueComparerTest.php 
b/tests/phpunit/CrossCheck/Comparer/TimeValueComparerTest.php
index 066a306..33f07e6 100644
--- a/tests/phpunit/CrossCheck/Comparer/TimeValueComparerTest.php
+++ b/tests/phpunit/CrossCheck/Comparer/TimeValueComparerTest.php
@@ -60,6 +60,11 @@
                $localValue2016 = new TimeValue( '+2016-03-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_MONTH, $g );
 
                return array(
+                       'Same second' => array(
+                               ComparisonResult::STATUS_MATCH,
+                               new TimeValue( '+2015-01-01T01:01:01Z', 0, 0, 
0, TimeValue::PRECISION_SECOND, $g ),
+                               new TimeValue( '+2015-01-01T01:01:01Z', 0, 0, 
0, TimeValue::PRECISION_SECOND, $g )
+                       ),
                        'Same day' => array(
                                ComparisonResult::STATUS_MATCH,
                                $localValue1955,
@@ -90,16 +95,41 @@
                                new TimeValue( '+11980-08-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_YEAR, $g ),
                                new TimeValue( '+1980-00-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_YEAR, $g )
                        ),
+                       'Other gigayear' => array(
+                               ComparisonResult::STATUS_MISMATCH,
+                               new TimeValue( '+1000000000-00-00T00:00:00Z', 
0, 0, 0, TimeValue::PRECISION_YEAR1G, $g ),
+                               new TimeValue( '+2000000000-00-00T00:00:00Z', 
0, 0, 0, TimeValue::PRECISION_YEAR1G, $g )
+                       ),
+                       'Other decade with year precision' => array(
+                               ComparisonResult::STATUS_MISMATCH,
+                               new TimeValue( '+2010-00-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_YEAR, $g ),
+                               new TimeValue( '+2020-00-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_YEAR, $g )
+                       ),
+                       'Other year with month precision' => array(
+                               ComparisonResult::STATUS_MISMATCH,
+                               new TimeValue( '+2001-01-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_MONTH, $g ),
+                               new TimeValue( '+2002-01-00T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_MONTH, $g )
+                       ),
                        'Other month with day precision' => array(
                                ComparisonResult::STATUS_MISMATCH,
                                new TimeValue( '+2001-01-01T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_DAY, $g ),
                                new TimeValue( '+2001-02-01T00:00:00Z', 0, 0, 
0, TimeValue::PRECISION_DAY, $g )
                        ),
+                       'Other day with hour precision' => array(
+                               ComparisonResult::STATUS_MISMATCH,
+                               new TimeValue( '+2001-01-01T01:00:00Z', 0, 0, 
0, TimeValue::PRECISION_HOUR, $g ),
+                               new TimeValue( '+2001-01-02T01:00:00Z', 0, 0, 
0, TimeValue::PRECISION_HOUR, $g )
+                       ),
                        'Other hour with minute precision' => array(
                                ComparisonResult::STATUS_MISMATCH,
                                new TimeValue( '+2001-01-01T01:01:00Z', 0, 0, 
0, TimeValue::PRECISION_MINUTE, $g ),
                                new TimeValue( '+2001-01-01T02:01:00Z', 0, 0, 
0, TimeValue::PRECISION_MINUTE, $g )
                        ),
+                       'Other minute with second precision' => array(
+                               ComparisonResult::STATUS_MISMATCH,
+                               new TimeValue( '+2001-01-01T01:01:01Z', 0, 0, 
0, TimeValue::PRECISION_SECOND, $g ),
+                               new TimeValue( '+2001-01-01T01:02:01Z', 0, 0, 
0, TimeValue::PRECISION_SECOND, $g )
+                       ),
                        // FIXME: This is a bug!
                        'Can not compare 5+ digit years' => array(
                                ComparisonResult::STATUS_MISMATCH,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibad8370656378dbf577b1530a99391f0e5a22e25
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityExternalValidation
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to