Skip to content

Commit f5daf44

Browse files
committed
chore: handle error when is a wrong date string
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 9e7b9d2 commit f5daf44

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

lib/Service/ReminderService.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Libresign\Service;
1010

11+
use DateMalformedStringException;
1112
use DateTime;
1213
use OCA\Libresign\AppInfo\Application;
1314
use OCA\Libresign\BackgroundJob\Reminder;
@@ -137,14 +138,18 @@ protected function getStartTime(string $startTime): ?\DateTime {
137138
$timezone = $this->dateTimeZone->getTimeZone();
138139

139140
$now = $this->time->getDateTime('now', new \DateTimeZone('UTC'));
140-
$dateTime = clone $now;
141-
$dateTime->modify('+1 day');
141+
$tomorrow = clone $now;
142+
$tomorrow->modify('+1 day');
142143

143-
$time = new \DateTime($startTime, $timezone);
144-
$dateTime->setTime((int)$time->format('H'), (int)$time->format('i'));
145-
$dateTime->setTimezone(new \DateTimeZone('UTC'));
144+
try {
145+
$time = new \DateTime($startTime, $timezone);
146+
} catch (DateMalformedStringException) {
147+
return null;
148+
}
149+
$tomorrow->setTime((int)$time->format('H'), (int)$time->format('i'));
150+
$tomorrow->setTimezone(new \DateTimeZone('UTC'));
146151

147-
return $dateTime;
152+
return $tomorrow;
148153
}
149154

150155
public function sendReminders(): void {

0 commit comments

Comments
 (0)