Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243132
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(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityExternalValidation
refs/changes/32/243132/1
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: newchange
Gerrit-Change-Id: Ibad8370656378dbf577b1530a99391f0e5a22e25
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityExternalValidation
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits