Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdentremont committed Sep 26, 2024
1 parent 4e444f4 commit 892a1e9
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/Plugin/Field/FieldFormatter/EDTFFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ protected function formatDate($edtf_text) {

// Replace Xs with 0s and format date parts
if ($unspecified_count > 0) {
if (strpos($year, 'X') !== FALSE)
if (strpos($year, 'X') !== FALSE) {
$year = str_replace('X', '0', $year) . 's';
}

if ($unspecified['fullyear']) {
$year = 'unknown year';
Expand Down Expand Up @@ -349,7 +350,7 @@ protected function formatDate($edtf_text) {
// Full dates will have a comma before the year, like January 1, 1999
// Dates with Xs in them will be written out more verbosely
$d = intval($day);
$day_suffix = date('S',mktime(1,1,1,1,( (($d>=10)+($d>=20)+($d==0))*10 + $d%10) ));
$day_suffix = date('S',mktime(1, 1, 1, 1, ((($d >= 10) + ($d >= 20) + ($d == 0)) * 10 + $d % 10)));
if ($settings['date_order'] === 'middle_endian' &&
!preg_match('/\d/', $month) &&
self::DELIMITERS[$settings['date_separator']] == ' ' &&
Expand All @@ -360,8 +361,9 @@ protected function formatDate($edtf_text) {
}
// Unknown month only
elseif($unspecified['month'] && $unspecified_count === 1) {
if ($day !== '')
if ($day !== '') {
$day .= "$day_suffix day of an";
}
$formatted_date = t(trim("$day $month, in $year"));
}
// Unknown day only
Expand All @@ -370,30 +372,37 @@ protected function formatDate($edtf_text) {
}
// Unknown year and month only
elseif(!$unspecified['day'] && $unspecified_count === 2) {
if ($day !== '')
if ($day !== '') {
$day .= "$day_suffix day of an";
if ($year == 'unknown year')
}
if ($year == 'unknown year') {
$formatted_date = t("$day $month, in an $year");
else
}
else {
$formatted_date = t(trim("$day $month, in the " . str_replace('unknown year in the ', '', $year)));
}
}
// Unknown year and day only
elseif(!$unspecified['month'] && $unspecified_count === 2) {
if ($year == 'unknown year')
if ($year == 'unknown year') {
$formatted_date = t("$day in $month, in an $year");
else
}
else {
$formatted_date = t("$day in $month, in the " . str_replace('unknown year in the ', '', $year));
}
}
// Unknown day and month only
elseif($unspecified['day'] && $unspecified['month'] && $unspecified_count === 2) {
$formatted_date = t("Unknown date, in $year");
}
// Unknown year, month, and day
elseif($unspecified_count === 3) {
if ($year == 'unknown year')
if ($year == 'unknown year') {
$formatted_date = t("Unknown day, month, and year");
else
}
else {
$formatted_date = t("Unknown date, in the " . str_replace('unknown year in the ', '', $year));
}
}
// No unknown segments
// Adds a comma after the month & day as long as there is at least one of them
Expand All @@ -406,8 +415,9 @@ protected function formatDate($edtf_text) {
}

// Capitalize first letter for unknown dates
if ($unspecified_count > 0)
if ($unspecified_count > 0) {
$formatted_date = ucfirst($formatted_date);
}

// Time.
// @todo Add time formatting options.
Expand Down

0 comments on commit 892a1e9

Please sign in to comment.