Skip to content

Commit

Permalink
EDTF Formatter Year configuration fix (Issue 2016) (#76)
Browse files Browse the repository at this point in the history
* Fix build

* persist EDTF year format setting

* Middle-endian special case

Fix for special case where middle-endian date order with spelled-out month and space separator should include a comma to separate the day and year.

* coding style
  • Loading branch information
seth-shaw-unlv authored Jan 26, 2022
1 parent 3835e2f commit 6854095
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Plugin/Field/FieldFormatter/EDTFFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
'#default_value' => $this->getSetting('year_format'),
'#options' => [
'ny' => t('Do not show year'),
'yy' => t('two-digit day of the month, e.g. 02'),
'yy' => t('two-digit representation of the year, e.g. 20'),
'y' => t('four-digit representation of the year, e.g. 2020'),
],
];
Expand Down Expand Up @@ -305,9 +305,11 @@ protected function formatDate($edtf_text) {
$parts_in_order = [$year, $month, $day];
}

// Special case for dates such as "Dec 29, 2021".
if ($settings['date_order'] === 'middle_endian' &&
!preg_match('/\d/', $month) &&
!empty(array_filter([$month, $day]))) {
self::DELIMITERS[$settings['date_separator']] == ' ' &&
count(array_filter([$year, $day])) == 2) {
$formatted_date = "$month $day, $year";
}
else {
Expand Down

0 comments on commit 6854095

Please sign in to comment.