示例#1
0
 /**
  * Set date value
  *
  * @param mixed $value
  * @return $this
  */
 public function setValue($value)
 {
     if (empty($value)) {
         $this->_value = '';
         return $this;
     }
     if ($value instanceof \DateTimeInterface) {
         $this->_value = $value;
         return $this;
     }
     if (preg_match('/^[0-9]+$/', $value)) {
         $this->_value = (new \DateTime())->setTimestamp($this->_toTimestamp($value));
         return $this;
     }
     try {
         $this->_value = new \DateTime($value, new \DateTimeZone($this->localeDate->getConfigTimezone()));
     } catch (\Exception $e) {
         $this->_value = '';
     }
     return $this;
 }
示例#2
0
 /**
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  */
 public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate)
 {
     $this->_localeDate = $localeDate;
     $this->_offset = $this->calculateOffset($this->_localeDate->getConfigTimezone());
 }
示例#3
0
 /**
  * Get formatted order created date in store timezone
  *
  * @param   string $format date format type (short|medium|long|full)
  * @return  string
  */
 public function getCreatedAtFormatted($format)
 {
     return $this->timezone->formatDateTime(new \DateTime($this->getCreatedAt()), $format, $format, null, $this->timezone->getConfigTimezone('store', $this->getStore()));
 }
示例#4
0
 /**
  * Check whether timestamps are from different days
  *
  * @param $timeA
  * @param $timeB
  * @param $storeId
  * @return bool
  */
 protected function areTimesDifferentDays($timeA, $timeB, $storeId)
 {
     if (!$timeA || !$timeB) {
         return true;
     }
     $timezone = $this->localeDate->getConfigTimezone(null, $storeId);
     $dateA = new \DateTime($timeA, new \DateTimeZone($this->localeDate->getDefaultTimezone()));
     $dateA->setTimezone(new \DateTimeZone($timezone));
     $dateB = new \DateTime($timeB, new \DateTimeZone($this->localeDate->getDefaultTimezone()));
     $dateB->setTimezone(new \DateTimeZone($timezone));
     return $dateA->format('Y-m-d') != $dateB->format('Y-m-d');
 }