Skip to content

Commit

Permalink
Merge pull request #519 from humhub/fix/locale-related-tests
Browse files Browse the repository at this point in the history
Fix Tests
  • Loading branch information
luke- authored Jan 13, 2025
2 parents 4558ac9 + dbdaf88 commit d0e1007
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-----------------------
Expand Down
18 changes: 18 additions & 0 deletions models/forms/CalendarEntryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
}

0 comments on commit d0e1007

Please sign in to comment.