Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/248895
Change subject: Always output 4-digit years in dates like "1 January 2"
......................................................................
Always output 4-digit years in dates like "1 January 2"
This is mostly critical for month and day precision because strings
like "January 2" are extremely confusing. The "2" is supposed to be
the year but is confused with the day.
For consistency year precision also uses 4-digit padding. A string
like "2" is also confusing, "0002" should be much more obvious.
Bug: T104750
Change-Id: I5ad2a098f524f130d479990eafabcc9fd6d7dc6f
---
M lib/includes/formatters/MwTimeIsoFormatter.php
M lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
2 files changed, 20 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/95/248895/1
diff --git a/lib/includes/formatters/MwTimeIsoFormatter.php
b/lib/includes/formatters/MwTimeIsoFormatter.php
index 0571d67..ba2fb57 100644
--- a/lib/includes/formatters/MwTimeIsoFormatter.php
+++ b/lib/includes/formatters/MwTimeIsoFormatter.php
@@ -280,7 +280,9 @@
}
}
- $year = str_pad( ltrim( $year, '0' ), 1, '0', STR_PAD_LEFT );
+ if ( $precision >= TimeValue::PRECISION_YEAR ) {
+ $year = str_pad( ltrim( $year, '0' ), 4, '0',
STR_PAD_LEFT );
+ }
if ( empty( $msg ) ) {
// TODO: This needs a message.
diff --git a/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
b/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
index 0277353..9985061 100644
--- a/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
+++ b/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
@@ -38,7 +38,7 @@
),
array(
'+00000000001-01-14T00:00:00Z',
TimeValue::PRECISION_DAY,
- '14 January 1',
+ '14 January 0001',
),
array(
'+00000010000-01-01T00:00:00Z',
TimeValue::PRECISION_DAY,
@@ -54,7 +54,7 @@
),
array(
'+00000000013-07-16T00:00:00Z',
TimeValue::PRECISION_YEAR,
- '13',
+ '0013',
),
array(
'+00002222013-07-16T00:10:00Z',
TimeValue::PRECISION_YEAR,
@@ -208,7 +208,7 @@
),
array(
'-00000000001-01-14T00:00:00Z',
TimeValue::PRECISION_DAY,
- '14 January 1 BCE',
+ '14 January 0001 BCE',
),
array(
'-00000010000-01-01T00:00:00Z',
TimeValue::PRECISION_DAY,
@@ -224,7 +224,7 @@
),
array(
'-00000000013-07-16T00:00:00Z',
TimeValue::PRECISION_YEAR,
- '13 BCE',
+ '0013 BCE',
),
array(
'-00002222013-07-16T00:10:00Z',
TimeValue::PRECISION_YEAR,
@@ -345,7 +345,7 @@
),
array(
'+5-01-00T00:00:00Z',
TimeValue::PRECISION_MONTH,
- 'January 5',
+ 'January 0005',
),
array(
'+00000001996-01-00T00:00:00Z',
TimeValue::PRECISION_MONTH,
@@ -357,7 +357,7 @@
),
array(
'+0-00-00T00:00:42Z', TimeValue::PRECISION_YEAR,
- '0',
+ '0000',
),
// centuries and millenia start with 1, so we can
format "low" years just fine
@@ -405,27 +405,27 @@
// Precision to low, falling back to year
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR1G,
- '1 BCE',
+ '0001 BCE',
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR100M,
- '1 BCE',
+ '0001 BCE',
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR10M,
- '1 BCE',
+ '0001 BCE',
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR1M,
- '1 BCE',
+ '0001 BCE',
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR100K,
- '1 BCE',
+ '0001 BCE',
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR10K,
- '1 BCE',
+ '0001 BCE',
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR1K,
@@ -437,17 +437,17 @@
),
array(
'-1-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR10,
- '1 BCE',
+ '0001 BCE',
),
// Better than the raw ISO string
array(
'-00000000000-01-01T01:01:01Z',
TimeValue::PRECISION_YEAR1G,
- '0 BCE',
+ '0000 BCE',
),
array(
'-0-01-01T01:01:01Z',
TimeValue::PRECISION_YEAR1G,
- '0 BCE',
+ '0000 BCE',
),
array(
'+100000000-00-00T00:00:00Z',
TimeValue::PRECISION_YEAR1G,
@@ -475,11 +475,11 @@
),
array(
'+1-00-00T00:00:08Z',
TimeValue::PRECISION_YEAR10,
- '1',
+ '0001',
),
array(
'-0-00-00T00:00:42Z', TimeValue::PRECISION_YEAR,
- '0 BCE',
+ '0000 BCE',
),
// Stuff we do not want to format so must return it :<
--
To view, visit https://gerrit.wikimedia.org/r/248895
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ad2a098f524f130d479990eafabcc9fd6d7dc6f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
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