Skip to content

Commit 0d6a4e6

Browse files
thomas-topway-itJeroenDeDauw
authored andcommitted
fix tests
1 parent d569714 commit 0d6a4e6

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/PackagePrivate/Humanizer/InternationalizedHumanizer.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,21 @@ private function scaleToMessageKey( int $scale ): string {
266266
return 'edtf-tens-of-trillions';
267267
}
268268

269-
private function humanizeYear( ExtDate $date ): string {
269+
private function humanizeYear( ExtDate $date ): string {
270+
$unspecifiedYearScale = $date->getUnspecifiedYearScale();
271+
$unspecifiedDigit = $date->getUnspecifiedDigit();
270272
$specifiedYears = $date->getSpecifiedYears();
273+
274+
if ( $unspecifiedYearScale === 0 ||
275+
( $this->needsYearEndingChar( $unspecifiedDigit ) && $specifiedYears !== 0 ) ) {
276+
return $this->humanizeYearSpecified( $date->getYear(), $unspecifiedDigit );
277+
}
278+
271279
$specifiedYearsStr = (string)abs( $specifiedYears );
272280

273-
$ret = ( $specifiedYears === 0 ? $this->message( "edtf-date-unspecified" )
281+
$ret = ( $specifiedYears === 0 && $unspecifiedYearScale != 0 ? $this->message( "edtf-date-unspecified" )
274282
: $specifiedYearsStr );
275283

276-
$unspecifiedYearScale = $date->getUnspecifiedYearScale();
277-
278284
if ( $unspecifiedYearScale > 0 ) {
279285
$ret .= " " . $this->message( $this->scaleToMessageKey( $unspecifiedYearScale ), $specifiedYearsStr );
280286
}
@@ -286,6 +292,26 @@ private function humanizeYear( ExtDate $date ): string {
286292
return $ret;
287293
}
288294

295+
private function humanizeYearSpecified( int $year, UnspecifiedDigit $unspecifiedDigit ): string {
296+
$yearStr = (string)abs( $year );
297+
298+
if ( $year <= -1000 ) {
299+
return $this->message( 'edtf-bc-year', $yearStr );
300+
}
301+
302+
if ( $year < 0 ) {
303+
return $this->message( 'edtf-bc-year-short', $yearStr );
304+
}
305+
306+
$endingChar = $this->needsYearEndingChar( $unspecifiedDigit ) ? 's' : '';
307+
308+
if ( $year < 1000 ) {
309+
return $this->message( 'edtf-year-short', $yearStr . $endingChar );
310+
}
311+
312+
return $yearStr . $endingChar;
313+
}
314+
289315
/**
290316
* Check, do we need to add 's' char to humanized year representation
291317
* This can be applicable to unspecified years i.e. 197X or 19XX

0 commit comments

Comments
 (0)