/** * Get instance of DateTime * * @return \Magento\Framework\Stdlib\DateTime\DateTime */ public function get() { if (!$this->dateTime) { $this->dateTime = $this->objectManagerProvider->get()->create('Magento\\Framework\\Stdlib\\DateTime\\DateTime', ['localeDate' => $this->tzProvider->get()]); } return $this->dateTime; }
public function testGet() { $timeZone = $this->getMock('\\Magento\\Framework\\Stdlib\\DateTime\\Timezone', [], [], '', false); $objectManager = $this->getMockForAbstractClass('\\Magento\\Framework\\ObjectManagerInterface', [], '', false); $objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\Stdlib\\DateTime\\Timezone', ['scopeType' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT])->willReturn($timeZone); /** @var ObjectManagerProvider|\PHPUnit_Framework_MockObject_MockObject $objectManagerProvider */ $objectManagerProvider = $this->getMock('\\Magento\\Setup\\Model\\ObjectManagerProvider', [], [], '', false); $objectManagerProvider->expects($this->any())->method('get')->willReturn($objectManager); $object = new TimeZoneProvider($objectManagerProvider); $this->assertSame($timeZone, $object->get()); // Assert that the provider always returns the same object $this->assertSame($timeZone, $object->get()); }
/** * Format a UTC timestamp (seconds since epoch) to structure expected by frontend * * @param string $syncDate seconds since epoch * @return array */ private function formatSyncDate($syncDate) { $timezone = $this->timeZoneProvider->get(); return ['date' => $timezone->formatDateTime(new \DateTime('@' . $syncDate), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE), 'time' => $timezone->formatDateTime(new \DateTime('@' . $syncDate), \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM)]; }