Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDTF Formatter Year configuration fix (Issue 2016) #76

Merged
merged 4 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
- name: Setup Mysql client
run: |
sudo apt-get update
sudo apt-get remove -y mysql-client mysql-common
sudo apt-get install -y mysql-client

- name: Set environment variables
Expand Down
7 changes: 5 additions & 2 deletions src/Plugin/Field/FieldFormatter/EDTFFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static function defaultSettings() {
// ISO 8601 bias.
'date_separator' => 'dash',
'date_order' => 'big_endian',
'year_format' => 'y',
'month_format' => 'mm',
'day_format' => 'dd',
] + parent::defaultSettings();
Expand Down Expand Up @@ -104,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 @@ -304,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