/** * @return array */ public function formatDateDataProvider() { // Take care when calling date here as it can be called much earlier than when testFormatDate // executes thus causing a discrepancy in the actual vs expected time. See MAGETWO-10296 $date = new \Magento\Framework\Stdlib\DateTime\Date(); return ['null' => [null, false, ''], 'null including Time' => [null, true, ''], 'Bool true' => [true, false, 'Y-m-d'], 'Bool true including Time' => [true, true, 'Y-m-d H:i:s'], 'Bool false' => [false, false, ''], 'Bool false including Time' => [false, true, ''], 'Zend Date' => [$date, false, date('Y-m-d', $date->getTimestamp())], 'Zend Date including Time' => [$date, true, date('Y-m-d H:i:s', $date->getTimestamp())]]; }
/** * Retrieve array of intervals * * @param string $from * @param string $to * @param string $period * @return array */ public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY) { $intervals = array(); if (!$from && !$to) { return $intervals; } $start = new \Magento\Framework\Stdlib\DateTime\Date($from, \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT); if ($period == self::REPORT_PERIOD_TYPE_DAY) { $dateStart = $start; } if ($period == self::REPORT_PERIOD_TYPE_MONTH) { $dateStart = new \Magento\Framework\Stdlib\DateTime\Date(date("Y-m", $start->getTimestamp()), DateTime::DATE_INTERNAL_FORMAT); } if ($period == self::REPORT_PERIOD_TYPE_YEAR) { $dateStart = new \Magento\Framework\Stdlib\DateTime\Date(date("Y", $start->getTimestamp()), DateTime::DATE_INTERNAL_FORMAT); } $dateEnd = new \Magento\Framework\Stdlib\DateTime\Date($to, DateTime::DATE_INTERNAL_FORMAT); while ($dateStart->compare($dateEnd) <= 0) { switch ($period) { case self::REPORT_PERIOD_TYPE_DAY: $t = $dateStart->toString('yyyy-MM-dd'); $dateStart->addDay(1); break; case self::REPORT_PERIOD_TYPE_MONTH: $t = $dateStart->toString('yyyy-MM'); $dateStart->addMonth(1); break; case self::REPORT_PERIOD_TYPE_YEAR: $t = $dateStart->toString('yyyy'); $dateStart->addYear(1); break; } $intervals[] = $t; } return $intervals; }
/** * Save report rows collected in settlement model * * @param \Magento\Framework\Model\AbstractModel|\Magento\Paypal\Model\Report\Settlement $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $rows = $object->getRows(); if (is_array($rows)) { $adapter = $this->_getWriteAdapter(); $reportId = (int) $object->getId(); try { $adapter->beginTransaction(); if ($reportId) { $adapter->delete($this->_rowsTable, array('report_id = ?' => $reportId)); } foreach (array_keys($rows) as $key) { /** * Converting dates */ $completionDate = new \Magento\Framework\Stdlib\DateTime\Date($rows[$key]['transaction_completion_date']); $rows[$key]['transaction_completion_date'] = $this->_coreDate->date(null, $completionDate->getTimestamp()); $initiationDate = new \Magento\Framework\Stdlib\DateTime\Date($rows[$key]['transaction_initiation_date']); $rows[$key]['transaction_initiation_date'] = $this->_coreDate->date(null, $initiationDate->getTimestamp()); /* * Converting numeric */ $rows[$key]['fee_amount'] = (double) $rows[$key]['fee_amount']; /* * Setting reportId */ $rows[$key]['report_id'] = $reportId; } if (!empty($rows)) { $adapter->insertMultiple($this->_rowsTable, $rows); } $adapter->commit(); } catch (\Exception $e) { $adapter->rollback(); } } return $this; }
/** * Return formatted option value for quote option * * @param string $optionValue Prepared for cart option value * @return string */ public function getFormattedOptionValue($optionValue) { if ($this->_formattedOptionValue === null) { $option = $this->getOption(); if ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE) { $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); $result = $this->_localeDate->date($optionValue, \Zend_Date::ISO_8601, null, false)->toString($format); } elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) { $format = $this->_localeDate->getDateTimeFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); $result = $this->_localeDate->date($optionValue, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT, null, false)->toString($format); } elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) { $date = new \Magento\Framework\Stdlib\DateTime\Date($optionValue); $result = date($this->is24hTimeFormat() ? 'H:i' : 'h:i a', $date->getTimestamp()); } else { $result = $optionValue; } $this->_formattedOptionValue = $result; } return $this->_formattedOptionValue; }