Skip to content

Commit

Permalink
Fix Certificate Format Date setUser Error
Browse files Browse the repository at this point in the history
  • Loading branch information
fhelfer authored and mjansenDatabay committed Sep 26, 2024
1 parent 59bb8ae commit 06aba7c
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ class ilCertificateDateHelper
public function formatDate($date, ilObjUser $user = null, ?int $dateFormat = null): string
{
if (null === $dateFormat) {
require_once __DIR__ . '/../../../Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
require_once __DIR__ . '/../../../Calendar/classes/class.ilDateTime.php'; // Required because of global constant IL_CAL_DATE
$dateFormat = IL_CAL_DATETIME;
}

$oldDatePresentationValue = ilDatePresentation::useRelativeDates();
ilDatePresentation::setUseRelativeDates(false);

if ($user) {
ilDatePresentation::setLanguage(new ilLanguage($user->getLanguage()));
ilDatePresentation::setUser($user);
}

$date = ilDatePresentation::formatDate(new ilDate($date, $dateFormat));

$date = ilDatePresentation::formatDate(
new ilDate($date, $dateFormat),
false,
false,
false,
$user
);
ilDatePresentation::setUseRelativeDates($oldDatePresentationValue);

return $date;
Expand All @@ -52,19 +51,20 @@ public function formatDate($date, ilObjUser $user = null, ?int $dateFormat = nul
public function formatDateTime($dateTime, ilObjuser $user = null, ?int $dateFormat = null): string
{
if (null === $dateFormat) {
require_once __DIR__ . '/../../../Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
require_once __DIR__ . '/../../../Calendar/classes/class.ilDateTime.php'; // Required because of global constant IL_CAL_DATE
$dateFormat = IL_CAL_DATETIME;
}

$oldDatePresentationValue = ilDatePresentation::useRelativeDates();
ilDatePresentation::setUseRelativeDates(false);

if ($user) {
ilDatePresentation::setLanguage(new ilLanguage($user->getLanguage()));
ilDatePresentation::setUser($user);
}

$date = ilDatePresentation::formatDate(new ilDateTime($dateTime, $dateFormat));
$date = ilDatePresentation::formatDate(
new ilDateTime($dateTime, $dateFormat),
false,
false,
false,
$user
);

ilDatePresentation::setUseRelativeDates($oldDatePresentationValue);

Expand Down

0 comments on commit 06aba7c

Please sign in to comment.