diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2211bdda..4919ca47 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,7 @@ Changelog - Fix #509: Fix event type visibility - Enh #512: Surround the widget wall entry links with a dedicated HTML class - Enh #516: Improved calendar page URLs +- Fix #519: Fix issue where `IntlDateFormatter::parse()` failed to parse Bulgarian dates. 1.6.4 (Unreleased) ----------------------- diff --git a/models/forms/CalendarEntryForm.php b/models/forms/CalendarEntryForm.php index 9ed1b831..b0efc8fa 100644 --- a/models/forms/CalendarEntryForm.php +++ b/models/forms/CalendarEntryForm.php @@ -379,6 +379,9 @@ public function load($data, $formName = null) $this->end_time = null; } + $this->start_date = $this->normalizeFormattedDate($this->start_date); + $this->end_date = $this->normalizeFormattedDate($this->end_date); + $startDT = $this->getStartDateTime(); $endDt = $this->getEndDateTime(); @@ -564,4 +567,19 @@ public function getEndDateTime() } return $endDT; } + + private function normalizeFormattedDate($formattedDate) + { + /** + * If the locale is 'bg' (Bulgarian), remove the 'г.' suffix from the date string. + * This suffix is automatically added by IntlDateFormatter::format() to indicate "year" in Bulgarian, + * but IntlDateFormatter::parse() fails to handle it properly, causing a parsing error. + * To ensure successful parsing, we normalize the date string by removing 'г.'. + */ + if (Yii::$app->formatter->locale == 'bg') { + return str_replace(' г.', '', $formattedDate); + } + + return $formattedDate; + } }