Skip to content

Commit 0eb44ce

Browse files
anzinxmav
authored andcommitted
Fixed code
1 parent 6ae79b7 commit 0eb44ce

File tree

3 files changed

+27
-10
lines changed
  • app/code/Magento/Config/Model/Config/Source/Date
  • dev/tests/integration/testsuite/Magento/Cron/Model
  • lib/internal/Magento/Framework/View/Element/Html

3 files changed

+27
-10
lines changed

app/code/Magento/Config/Model/Config/Source/Date/Short.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Config\Model\Config\Source\Date;
77

88
use IntlDateFormatter;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Locale\ResolverInterface;
911

1012
/**
1113
* @api
@@ -43,8 +45,12 @@ public function toOptionArray()
4345
private function getTimeFormat(int $datetime, string $format = 'Y/M/d'): string
4446
{
4547
if (!$this->dateFormatter) {
46-
$locale = \Locale::getDefault();
47-
$this->dateFormatter = new \IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
48+
$localeResolver = ObjectManager::getInstance()->get(ResolverInterface::class);
49+
$this->dateFormatter = new \IntlDateFormatter(
50+
$localeResolver->getLocale(),
51+
IntlDateFormatter::SHORT,
52+
IntlDateFormatter::SHORT
53+
);
4854
}
4955
$this->dateFormatter->setPattern($format);
5056

dev/tests/integration/testsuite/Magento/Cron/Model/ScheduleTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Cron\Model;
77

88
use IntlDateFormatter;
9+
use Magento\Framework\Locale\ResolverInterface;
910
use Magento\Framework\Stdlib\DateTime\DateTime;
1011
use \Magento\TestFramework\Helper\Bootstrap;
1112

@@ -76,8 +77,8 @@ public function testTryLockJobAlreadyLockedSucceeds()
7677
->setJobCode("test_job")
7778
->setStatus(Schedule::STATUS_RUNNING)
7879
->setCreatedAt($this->getTimeFormat($gmtTimestamp - $offsetInThePast))
79-
->setScheduledAt($this->getTimeFormat($gmtTimestamp - $offsetInThePast + 60, 'Y-M-d H:m'))
80-
->setExecutedAt($this->getTimeFormat($gmtTimestamp - $offsetInThePast + 61, 'Y-M-d H:m'));
80+
->setScheduledAt($this->getTimeFormat($gmtTimestamp - $offsetInThePast + 60, 'Y-M-d HH:mm'))
81+
->setExecutedAt($this->getTimeFormat($gmtTimestamp - $offsetInThePast + 61, 'Y-M-d HH:mm'));
8182
$oldSchedule->save();
8283

8384
$schedule = $this->createSchedule("test_job", Schedule::STATUS_PENDING);
@@ -124,7 +125,7 @@ private function createSchedule($jobCode, $status, $timeOffset = 0)
124125
->setJobCode($jobCode)
125126
->setStatus($status)
126127
->setCreatedAt($this->getTimeFormat($gmtTimestamp))
127-
->setScheduledAt($this->getTimeFormat($gmtTimestamp + $timeOffset, 'Y-M-d H:m'));
128+
->setScheduledAt($this->getTimeFormat($gmtTimestamp + $timeOffset, 'Y-M-d HH:mm'));
128129
$schedule->save();
129130

130131
return $schedule;
@@ -138,11 +139,15 @@ private function createSchedule($jobCode, $status, $timeOffset = 0)
138139
*
139140
* @return string
140141
*/
141-
private function getTimeFormat(int $datetime, string $format = 'Y-M-d H:m:s'): string
142+
private function getTimeFormat(int $datetime, string $format = 'Y-M-d HH:mm:ss'): string
142143
{
143144
if (!$this->dateFormatter) {
144-
$locale = \Locale::getDefault();
145-
$this->dateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
145+
$localeResolver = Bootstrap::getObjectManager()->create(ResolverInterface::class);
146+
$this->dateFormatter = new IntlDateFormatter(
147+
$localeResolver->getLocale(),
148+
IntlDateFormatter::SHORT,
149+
IntlDateFormatter::SHORT
150+
);
146151
}
147152
$this->dateFormatter->setPattern($format);
148153

lib/internal/Magento/Framework/View/Element/Html/Date.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Framework\View\Element\Html;
77

88
use IntlDateFormatter;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Locale\ResolverInterface;
911

1012
/**
1113
* Date element block
@@ -78,8 +80,12 @@ protected function _toHtml()
7880
public function getEscapedValue()
7981
{
8082
if ($this->getFormat() && $this->getValue()) {
81-
$locale = \Locale::getDefault();
82-
$dateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
83+
$localeResolver = ObjectManager::getInstance()->get(ResolverInterface::class);
84+
$dateFormatter = new IntlDateFormatter(
85+
$localeResolver->getLocale(),
86+
IntlDateFormatter::SHORT,
87+
IntlDateFormatter::SHORT
88+
);
8389
$dateFormatter->setPattern($this->getFormat());
8490

8591
return $dateFormatter->format(strtotime($this->getValue()));

0 commit comments

Comments
 (0)