Skip to content

Commit c1fc323

Browse files
authored
Merge pull request #4693 from nextcloud/fix/confirmation-mail-time-zone
Apply time zone to dates in confimation mail
2 parents 62a4e33 + 450642e commit c1fc323

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
All notable changes to this project will be documented in this file.
77
## [Unreleased]
88
- Support Nextcloud 34 (Hub 26 Spring)
9+
- Make modal for sending out confirmations closeable
10+
- Apply time zone to confirmation mail
911

1012
## [9.1.1] - 2026-05-06
1113
### Fixed
1214
- Fix repairstep which deleted the display names from shares
13-
- Make modal for sending out confirmations closeable
1415

1516
### Changed
1617
- Set default sort to last activity (renamed from last interaction) for poll list, navigation and dashboard

lib/Model/Mail/ConfirmationMail.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OCA\Polls\Model\Mail;
1111

12+
use DateTimeZone;
1213
use OCA\Polls\AppInfo\Application;
1314
use OCA\Polls\Db\Option;
1415
use OCA\Polls\Db\Poll;
@@ -47,18 +48,21 @@ protected function buildBody(): void {
4748
$this->l10n->n('Confirmed option:', 'Confirmed options:', count($this->confirmedOptions))
4849
);
4950

51+
$useTimeZoneName = $this->poll->getTimezoneName() ?? $this->recipient->getTimeZoneName();
52+
$useTimeZone = new DateTimeZone($useTimeZoneName);
53+
5054
$localizedDateSpan = new DateTimeIntervalText($this->l10n);
5155

5256
foreach ($this->confirmedOptions as $option) {
5357
if ($this->poll->getType() === Poll::TYPE_DATE) {
54-
$dateTime = $option->getDateTime();
58+
$dateTime = $option->getDateTime()->setTimeZone($useTimeZone);
5559

5660
if ($dateTime->getISO() === null) {
5761
continue;
5862
}
5963

6064
$localizedDateSpan
61-
->setStartDateTime($option->getDateTime())
65+
->setStartDateTime($dateTime)
6266
->setInterval($option->getInterval());
6367

6468
$this->emailTemplate->addBodyListItem(
@@ -72,7 +76,7 @@ protected function buildBody(): void {
7276

7377
if ($this->poll->getType() === Poll::TYPE_DATE) {
7478
$this->emailTemplate->addBodyText(
75-
$this->l10n->t('The used time zone is "%s", based on the detected time zone at your registration time. To view the times in your current time zone, enter the poll by clicking the button below.', $this->recipient->getTimeZoneName())
79+
$this->l10n->t('The used time zone is "%s". To view the times in your current time zone, enter the poll by clicking the button below.', $useTimeZoneName)
7680
);
7781
}
7882

lib/Model/UserBase.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use OCA\Polls\Model\User\User;
2525
use OCA\Polls\UserSession;
2626
use OCP\Collaboration\Collaborators\ISearch;
27-
use OCP\IDateTimeZone;
2827
use OCP\IGroupManager;
2928
use OCP\IL10N;
3029
use OCP\Share\IShare;
@@ -69,7 +68,6 @@ class UserBase implements JsonSerializable {
6968
protected string $description = '';
7069
protected string $richObjectType = self::TYPE_USER;
7170
protected string $organisation = '';
72-
protected IDateTimeZone $timeZone;
7371
protected IGroupManager $groupManager;
7472
protected IL10N $l10n;
7573
protected UserSession $userSession;
@@ -86,7 +84,6 @@ public function __construct(
8684
) {
8785
$this->l10n = Container::getL10N();
8886
$this->groupManager = Container::queryClass(IGroupManager::class);
89-
$this->timeZone = Container::queryClass(IDateTimeZone::class);
9087
$this->userSession = Container::queryClass(UserSession::class);
9188
$this->appSettings = Container::queryClass(AppSettings::class);
9289
}
@@ -172,14 +169,14 @@ public function getLocaleCodeIntl(): string {
172169
}
173170

174171
public function getTimeZone(): DateTimeZone {
175-
if ($this->timeZoneName) {
176-
return new DateTimeZone($this->timeZoneName);
177-
}
178-
return new DateTimeZone($this->timeZone->getTimeZone()->getName());
172+
return new DateTimeZone($this->timeZoneName);
179173
}
180174

181175
public function getTimeZoneName(): string {
182-
return $this->timeZoneName;
176+
if ($this->timeZoneName) {
177+
return $this->timeZoneName;
178+
}
179+
return date_default_timezone_get();
183180
}
184181

185182
public function getDisplayName(): string {

0 commit comments

Comments
 (0)