Skip to content

Commit 6bda779

Browse files
committed
Convert internationalized date into DateTime object
1 parent c4fa85b commit 6bda779

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

app/code/Magento/Newsletter/Model/Queue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function setQueueStartAtByString($startAt)
196196
if ($startAt === null || $startAt == '') {
197197
$this->setQueueStartAt(null);
198198
} else {
199-
$startAt = $this->timezone->convertConfigTimeToUtc($startAt, null);
199+
$startAt = $this->timezone->convertConfigTimeToUtcWithPattern($startAt, 'Y-m-d H:i:s', null);
200200
$this->setQueueStartAt($startAt);
201201
}
202202
return $this;

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,25 @@ public function formatDateTime(
306306
* @param string $format
307307
* @throws LocalizedException
308308
* @return string
309+
* @deprecated
309310
*/
310311
public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
312+
{
313+
return $this->convertConfigTimeToUtcWithPattern($date, $format);
314+
}
315+
316+
/**
317+
* Convert date from config timezone to Utc.
318+
* If pass \DateTime object as argument be sure that timezone is the same with config timezone
319+
*
320+
* @param string|\DateTimeInterface $date
321+
* @param string $format
322+
* @param string $pattern
323+
* @throws LocalizedException
324+
* @return string
325+
* @deprecated
326+
*/
327+
public function convertConfigTimeToUtcWithPattern($date, $format = 'Y-m-d H:i:s', $pattern = 'Y-M-dd HH:mm:ss')
311328
{
312329
if (!($date instanceof \DateTimeInterface)) {
313330
if ($date instanceof \DateTimeImmutable) {
@@ -319,7 +336,7 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
319336
\IntlDateFormatter::MEDIUM,
320337
$this->getConfigTimezone(),
321338
null,
322-
$format
339+
$pattern
323340
);
324341
$unixTime = $formatter->parse($date);
325342
$dateTime = new DateTime($this);
@@ -343,6 +360,7 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
343360
return $date->format($format);
344361
}
345362

363+
346364
/**
347365
* Retrieve date with time
348366
*

lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ public function formatDateTime(
143143
* @param string $format
144144
* @return string
145145
* @since 100.1.0
146+
* @deprecated
146147
*/
147148
public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s');
149+
150+
/**
151+
* @param $date
152+
* @param string $format
153+
* @param string $pattern
154+
* @return mixed
155+
*/
156+
public function convertConfigTimeToUtcWithPattern($date, $format = 'Y-m-d H:i:s', $pattern = 'Y-m-d H:i:s');
148157
}

0 commit comments

Comments
 (0)