jenkins-bot has submitted this change and it was merged. Change subject: Always display calendar name for dates not Gregorian > 1581 ......................................................................
Always display calendar name for dates not Gregorian > 1581 Change-Id: Ic6939bcbedef5b56ea46600ec5419b6526bb12b2 --- M lib/includes/formatters/HtmlTimeFormatter.php M lib/tests/phpunit/formatters/HtmlTimeFormatterTest.php 2 files changed, 25 insertions(+), 7 deletions(-) Approvals: Adrian Lang: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/includes/formatters/HtmlTimeFormatter.php b/lib/includes/formatters/HtmlTimeFormatter.php index 057cca2..2ead58d 100644 --- a/lib/includes/formatters/HtmlTimeFormatter.php +++ b/lib/includes/formatters/HtmlTimeFormatter.php @@ -29,6 +29,10 @@ */ private $dateTimeFormatter; + /** + * @param FormatterOptions $options + * @param ValueFormatter $dateTimeFormatter + */ public function __construct( FormatterOptions $options, ValueFormatter $dateTimeFormatter ) { $this->dateTimeFormatter = $dateTimeFormatter; @@ -65,25 +69,31 @@ * Display the calendar being used if the date lies within a time frame when * multiple calendars have been in use or if the time value features a calendar that * is uncommon for the specified time. + * + * @param TimeValue $value + * @return string */ private function formatOptionalCalendarName( TimeValue $value ) { return $this->calendarNameNeeded( $value ) ? $this->formatCalendarName( $value ) : ''; } + /** + * @param TimeValue $value + * @return bool + */ private function calendarNameNeeded( TimeValue $value ) { preg_match( '/^[+-](\d+)-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/', $value->getTime(), $matches ); $year = intval( $matches[1] ); $calendar = $this->getCalendarKey( $value->getCalendarModel() ); - return $value->getPrecision() > 10 - && ( - $year > 1581 && $year < 1930 - || $year <= 1581 && $calendar === 'gregorian' - || $year >= 1930 && $calendar === 'julian' - ); + return $value->getPrecision() > 10 && ( $year <= 1581 || $calendar !== 'gregorian' ); } + /** + * @param TimeValue $value + * @return string + */ private function formatCalendarName( TimeValue $value ) { $calendarKey = $this->getCalendarKey( $value->getCalendarModel() ); return $this->getMessage( 'valueview-expert-timevalue-calendar-' . $calendarKey ); diff --git a/lib/tests/phpunit/formatters/HtmlTimeFormatterTest.php b/lib/tests/phpunit/formatters/HtmlTimeFormatterTest.php index b5cd8ae..9d7a38e 100644 --- a/lib/tests/phpunit/formatters/HtmlTimeFormatterTest.php +++ b/lib/tests/phpunit/formatters/HtmlTimeFormatterTest.php @@ -48,7 +48,7 @@ TimeValue::PRECISION_DAY, TimeFormatter::CALENDAR_GREGORIAN ), new FormatterOptions(), - '/^MOCKDATE <sup class="wb-calendar-name">Gregorian<\/sup>$/' + '/^MOCKDATE$/' ), 'a julian day in 1920' => array( new TimeValue( '+1920-05-01T00:00:00Z', @@ -74,6 +74,14 @@ new FormatterOptions(), '/^MOCKDATE <sup class="wb-calendar-name">Gregorian<\/sup>$/' ), + 'a julian day in 1520' => array( + new TimeValue( '+1520-05-01T00:00:00Z', + 1 * 60 * 60, 0, 0, + TimeValue::PRECISION_DAY, + TimeFormatter::CALENDAR_JULIAN ), + new FormatterOptions(), + '/^MOCKDATE <sup class="wb-calendar-name">Julian<\/sup>$/' + ), 'a julian day in 1980' => array( new TimeValue( '+1980-05-01T00:00:00Z', 1 * 60 * 60, 0, 0, -- To view, visit https://gerrit.wikimedia.org/r/172683 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic6939bcbedef5b56ea46600ec5419b6526bb12b2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de> Gerrit-Reviewer: Adrian Lang <adrian.l...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits