Skip to content

Commit e949976

Browse files
MAGETWO-97866: [Magento Cloud] news_from_date and news_to_date dates incorrect in database with scheduled updates
Due to unstable work of intl parsing on different platforms
1 parent ba4053a commit e949976

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class Schedule extends \Magento\Framework\Model\AbstractModel
6262
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
6363
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
6464
* @param array $data
65-
* @param TimezoneInterface $timezoneConverter
66-
* @param DateTimeFactory $dateTimeFactory
65+
* @param TimezoneInterface|null $timezoneConverter
66+
* @param DateTimeFactory|null $dateTimeFactory
6767
*/
6868
public function __construct(
6969
\Magento\Framework\Model\Context $context,
@@ -125,7 +125,7 @@ public function trySchedule()
125125
if (!is_numeric($time)) {
126126
//convert time from UTC to admin store timezone
127127
//we assume that all schedules in configuration (crontab.xml and DB tables) are in admin store timezone
128-
$dateTimeUtc = $this->dateTimeFactory->create($time, new \DateTimeZone('UTC'));
128+
$dateTimeUtc = $this->dateTimeFactory->create($time);
129129
$time = $dateTimeUtc->getTimestamp();
130130
}
131131
$time = $storeDateTime->setTimestamp($time);

app/code/Magento/Cron/Test/Unit/Model/ScheduleTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ public function testTrySchedule($scheduledAt, $cronExprArr, $expected): void
206206
->willReturn('UTC');
207207

208208
$this->dateTimeFactory->method('create')
209-
->willReturn(new \DateTime(null, new \DateTimeZone('UTC')));
209+
->willReturn(new \DateTime());
210210

211211
/** @var \Magento\Cron\Model\Schedule $model */
212212
$model = $this->helper->getObject(
213213
\Magento\Cron\Model\Schedule::class,
214214
[
215215
'timezoneConverter' => $this->timezoneConverter,
216-
'dateTimeFactory' => $this->dateTimeFactory
216+
'dateTimeFactory' => $this->dateTimeFactory,
217217
]
218218
);
219219

@@ -242,14 +242,14 @@ public function testTryScheduleWithConversionToAdminStoreTime(): void
242242
->willReturn('UTC');
243243

244244
$this->dateTimeFactory->method('create')
245-
->willReturn(new \DateTime(null, new \DateTimeZone('UTC')));
245+
->willReturn(new \DateTime());
246246

247247
/** @var \Magento\Cron\Model\Schedule $model */
248248
$model = $this->helper->getObject(
249249
\Magento\Cron\Model\Schedule::class,
250250
[
251251
'timezoneConverter' => $this->timezoneConverter,
252-
'dateTimeFactory' => $this->dateTimeFactory
252+
'dateTimeFactory' => $this->dateTimeFactory,
253253
]
254254
);
255255

@@ -272,7 +272,7 @@ public function testTryScheduleWithConversionToAdminStoreTime(): void
272272
public function tryScheduleDataProvider(): array
273273
{
274274
$date = '2011-12-13 14:15:16';
275-
$timestamp = (new \DateTime($date, new \DateTimeZone('UTC')))->getTimestamp();
275+
$timestamp = (new \DateTime($date))->getTimestamp();
276276
$day = 'Monday';
277277
return [
278278
[$date, [], false],
@@ -286,7 +286,7 @@ public function tryScheduleDataProvider(): array
286286
[$timestamp, ['*', '14', '*', '*', '*'], true],
287287
[$timestamp, ['*', '*', '13', '*', '*'], true],
288288
[$timestamp, ['*', '*', '*', '12', '*'], true],
289-
[(new \DateTime($day, new \DateTimeZone('UTC')))->getTimestamp(), ['*', '*', '*', '*', '1'], true],
289+
[(new \DateTime($day))->getTimestamp(), ['*', '*', '*', '*', '1'], true],
290290
];
291291
}
292292

0 commit comments

Comments
 (0)