Skip to content

Commit

Permalink
Misc: Add formatted function to render timestamp based on user locale…
Browse files Browse the repository at this point in the history
… preferences
  • Loading branch information
Akshay Kumar committed Feb 14, 2023
1 parent 0d4497e commit d4ca796
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,46 @@ public function getWebsiteDetails($code)

public function convertToTimezone($date, $format = "d-m-Y H:ia")
{
if(!$date)
if (!$date) {
return "N/A";
$currentUser = $this->getCurrentUser();
$date = date_format($date,$format);
$dateTime = date('Y-m-d H:i:s',strtotime($date));
$scheduleDate = new \DateTime($dateTime, new \DateTimeZone(date_default_timezone_get()));
$this->domain = $this->container->get('router')->getContext()->getHost();
}

$scheduleDate->setTimeZone(new \DateTimeZone('Asia/Kolkata'));
$date = date_format($date, $format);
$dateTime = date('Y-m-d H:i:s', strtotime($date));

$scheduleDate = new \DateTime($dateTime, new \DateTimeZone(date_default_timezone_get()));
$scheduleDate
->setTimeZone(new \DateTimeZone('Asia/Kolkata'))
;

return $scheduleDate->format($format);
}

public function convertDateTimeToSupportedUserTimeFormat(\DateTime $date, $timezone = "Asia/Kolkata", $timeformat = "d-m-Y H:ia")
{
if (empty($date)) {
return "N/A";
}

$currentUser = $this->getCurrentUser();

if (!empty($currentUser)) {
if ($currentUser->getTimezone() != null) {
$timezone = $currentUser->getTimezone();
}

if ($currentUser->getTimeFormat() != null) {
$timeformat = $currentUser->getTimeFormat();
}
}

$date
->setTimeZone(new \DateTimeZone($timezone))
;

return $date->format($timeformat);
}

public function convertToDatetimeTimezoneTimestamp($date, $format = "d-m-Y h:ia")
{
if(!$date)
Expand Down

0 comments on commit d4ca796

Please sign in to comment.