Skip to content

Commit 310648c

Browse files
authored
Merge pull request #3775 from magento-tsg-csl3/2.3-develop-pr16
[TSG-CSL3] For 2.3 (pr16)
2 parents 10f900e + de9c950 commit 310648c

File tree

12 files changed

+835
-136
lines changed

12 files changed

+835
-136
lines changed

app/code/Magento/Cron/Model/Schedule.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Exception\CronException;
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
12+
use Magento\Framework\Intl\DateTimeFactory;
1213

1314
/**
1415
* Crontab schedule model
@@ -50,24 +51,32 @@ class Schedule extends \Magento\Framework\Model\AbstractModel
5051
*/
5152
private $timezoneConverter;
5253

54+
/**
55+
* @var DateTimeFactory
56+
*/
57+
private $dateTimeFactory;
58+
5359
/**
5460
* @param \Magento\Framework\Model\Context $context
5561
* @param \Magento\Framework\Registry $registry
5662
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
5763
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
5864
* @param array $data
59-
* @param TimezoneInterface $timezoneConverter
65+
* @param TimezoneInterface|null $timezoneConverter
66+
* @param DateTimeFactory|null $dateTimeFactory
6067
*/
6168
public function __construct(
6269
\Magento\Framework\Model\Context $context,
6370
\Magento\Framework\Registry $registry,
6471
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
6572
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
6673
array $data = [],
67-
TimezoneInterface $timezoneConverter = null
74+
TimezoneInterface $timezoneConverter = null,
75+
DateTimeFactory $dateTimeFactory = null
6876
) {
6977
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
7078
$this->timezoneConverter = $timezoneConverter ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
79+
$this->dateTimeFactory = $dateTimeFactory ?: ObjectManager::getInstance()->get(DateTimeFactory::class);
7180
}
7281

7382
/**
@@ -111,17 +120,20 @@ public function trySchedule()
111120
if (!$e || !$time) {
112121
return false;
113122
}
123+
$configTimeZone = $this->timezoneConverter->getConfigTimezone();
124+
$storeDateTime = $this->dateTimeFactory->create(null, new \DateTimeZone($configTimeZone));
114125
if (!is_numeric($time)) {
115126
//convert time from UTC to admin store timezone
116127
//we assume that all schedules in configuration (crontab.xml and DB tables) are in admin store timezone
117-
$time = $this->timezoneConverter->date($time)->format('Y-m-d H:i');
118-
$time = strtotime($time);
128+
$dateTimeUtc = $this->dateTimeFactory->create($time);
129+
$time = $dateTimeUtc->getTimestamp();
119130
}
120-
$match = $this->matchCronExpression($e[0], strftime('%M', $time))
121-
&& $this->matchCronExpression($e[1], strftime('%H', $time))
122-
&& $this->matchCronExpression($e[2], strftime('%d', $time))
123-
&& $this->matchCronExpression($e[3], strftime('%m', $time))
124-
&& $this->matchCronExpression($e[4], strftime('%w', $time));
131+
$time = $storeDateTime->setTimestamp($time);
132+
$match = $this->matchCronExpression($e[0], $time->format('i'))
133+
&& $this->matchCronExpression($e[1], $time->format('H'))
134+
&& $this->matchCronExpression($e[2], $time->format('d'))
135+
&& $this->matchCronExpression($e[3], $time->format('m'))
136+
&& $this->matchCronExpression($e[4], $time->format('w'));
125137

126138
return $match;
127139
}

0 commit comments

Comments
 (0)