Skip to content

Commit 85fefe2

Browse files
committed
fix: time > now, today; time < now , tomorrow
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent a01ead1 commit 85fefe2

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

lib/Service/ReminderService.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,20 @@ protected function getStartTime(string $startTime): ?\DateTime {
138138
$timezone = $this->dateTimeZone->getTimeZone();
139139

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

144143
try {
145144
$time = new \DateTime($startTime, $timezone);
146145
} catch (DateMalformedStringException) {
147146
return null;
148147
}
149-
$tomorrow->setTime((int)$time->format('G'), (int)$time->format('i'));
150-
$tomorrow->setTimezone(new \DateTimeZone('UTC'));
148+
$dateTime->setTime((int)$time->format('G'), (int)$time->format('i'));
149+
$dateTime->setTimezone(new \DateTimeZone('UTC'));
150+
if ($dateTime <= $now) {
151+
$dateTime->modify('+1 day');
152+
}
151153

152-
return $tomorrow;
154+
return $dateTime;
153155
}
154156

155157
public function sendReminders(): void {

tests/php/Unit/Service/ReminderServiceTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public static function providerSave(): array {
420420
'days_before' => 1,
421421
'days_between' => 1,
422422
'max' => 1,
423-
'next_run' => (clone $now)->modify('+1 day')->setTime(10, 0),
423+
'next_run' => (clone $now)->setTime(10, 0),
424424
'send_timer' => '10:00',
425425
],
426426
],
@@ -430,17 +430,27 @@ public static function providerSave(): array {
430430
'days_before' => 1,
431431
'days_between' => 1,
432432
'max' => 1,
433-
'next_run' => (clone $now)->modify('+1 day')->setTime(10, 0),
433+
'next_run' => (clone $now)->setTime(10, 0),
434434
'send_timer' => '10:00',
435435
],
436436
],
437+
[
438+
'daysBefore' => 1, 'daysBetween' => 1, 'max' => 1, 'sendTimer' => '08:05',
439+
'expected' => [
440+
'days_before' => 1,
441+
'days_between' => 1,
442+
'max' => 1,
443+
'next_run' => (clone $now)->modify('+1 day')->setTime(8, 5),
444+
'send_timer' => '08:05',
445+
],
446+
],
437447
[
438448
'daysBefore' => 1, 'daysBetween' => 1, 'max' => 1, 'sendTimer' => '11:05',
439449
'expected' => [
440450
'days_before' => 1,
441451
'days_between' => 1,
442452
'max' => 1,
443-
'next_run' => (clone $now)->modify('+1 day')->setTime(11, 5),
453+
'next_run' => (clone $now)->setTime(11, 5),
444454
'send_timer' => '11:05',
445455
],
446456
],

0 commit comments

Comments
 (0)