Skip to content

Commit

Permalink
getting default timezone for local time
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Ilkiv <a.ilkiv.ye@gmail.com>
  • Loading branch information
AIlkiv committed Nov 5, 2024
1 parent 4a44d6a commit 3d2f2e4
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;
use OCA\DAV\CalDAV\TimezoneService;

class LocalTimeProvider implements IProvider {
public function __construct(
Expand All @@ -28,14 +29,15 @@ public function __construct(
private ITimeFactory $timeFactory,
private IDateTimeFormatter $dateTimeFormatter,
private IConfig $config,
private TimezoneService $timezoneService,
) {
}

public function process(IEntry $entry): void {
$targetUserId = $entry->getProperty('UID');
$targetUser = $this->userManager->get($targetUserId);
if (!empty($targetUser)) {
$timezone = $this->config->getUserValue($targetUser->getUID(), 'core', 'timezone') ?: date_default_timezone_get();
$timezone = $this->config->getUserValue($targetUser->getUID(), 'core', 'timezone', $this->timezoneService->getDefaultTimezone());
$dateTimeZone = new \DateTimeZone($timezone);
$localTime = $this->dateTimeFormatter->formatTime($this->timeFactory->getDateTime(), 'short', $dateTimeZone);

Expand Down

0 comments on commit 3d2f2e4

Please sign in to comment.