mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Fixed: a bug for range generatoion during week-end
The range generator failed during week-end, because no range is selected (lastStart and endDate is null). with this commit, the rangeGenerator may return null instead of an array, which means no sms will be send.
This commit is contained in:
@@ -51,8 +51,13 @@ class CalendarForShortMessageProvider
|
||||
*/
|
||||
public function getCalendars(DateTimeImmutable $at): iterable
|
||||
{
|
||||
['startDate' => $startDate, 'endDate' => $endDate] = $this->rangeGenerator
|
||||
->generateRange($at);
|
||||
$range = $this->rangeGenerator->generateRange($at);
|
||||
|
||||
if (null === $range) {
|
||||
return;
|
||||
}
|
||||
|
||||
['startDate' => $startDate, 'endDate' => $endDate] = $range;
|
||||
|
||||
$offset = 0;
|
||||
$batchSize = 10;
|
||||
|
@@ -31,14 +31,14 @@ use UnexpectedValueException;
|
||||
*/
|
||||
class DefaultRangeGenerator implements RangeGeneratorInterface
|
||||
{
|
||||
public function generateRange(\DateTimeImmutable $date): array
|
||||
public function generateRange(\DateTimeImmutable $date): ?array
|
||||
{
|
||||
$onMidnight = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d') . ' 00:00:00');
|
||||
|
||||
switch ($dow = (int) $onMidnight->format('w')) {
|
||||
case 6: // Saturday
|
||||
case 0: // Sunday
|
||||
return ['startDate' => null, 'endDate' => null];
|
||||
return null;
|
||||
|
||||
case 1: // Monday
|
||||
// send for Tuesday and Wednesday
|
||||
|
@@ -23,7 +23,7 @@ use DateTimeImmutable;
|
||||
interface RangeGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @return array<startDate: \DateTimeImmutable, endDate: \DateTimeImmutable>
|
||||
* @return ?array{startDate: DateTimeImmutable, endDate: DateTimeImmutable} when return is null, then no ShortMessage must be send
|
||||
*/
|
||||
public function generateRange(DateTimeImmutable $date): array;
|
||||
public function generateRange(DateTimeImmutable $date): ?array;
|
||||
}
|
||||
|
Reference in New Issue
Block a user