/** * @param array $params * @param Di $di * @return array */ public static function convertDate(array $params, Di $di) { foreach ($params as $key => $value) { if (!is_string($value) or !self::isDate($value) or !strtotime($value)) { continue; } try { $timezoneOffset = self::getTimezoneOffset($di); $moment = new Moment($value, 'CET'); if ($timezoneOffset > 0) { $moment->subtractMinutes(abs($timezoneOffset)); } if ($timezoneOffset < 0) { $moment->addMinutes(abs($timezoneOffset)); } $params[$key] = $moment->format('Y-m-d H:i:s'); } catch (MomentException $exception) { } } return $params; }
public function init() { parent::init(); $this->sourceCurrency = self::SOURCE_CURRENCY; if ($this->exchangeRateDate == NULL) { $this->exchangeRateDate = new Moment(); } elseif (is_string($this->exchangeRateDate)) { $this->exchangeRateDate = new Moment($this->exchangeRateDate); } $today = new Moment(); if ($today->isBefore($this->exchangeRateDate)) { throw new CurrencyExchangeRateException('You cannot get exchange rate for future. Today:' . $today->format() . ' Request date:' . $this->exchangeRateDate->format()); } if ($this->linkDir == null) { $this->linkDir = 'http://www.nbp.pl/kursy/xml'; } if ($this->linkList == null) { $year = ''; if ($this->exchangeRateDate->getYear() != $today->getYear()) { $year = $this->exchangeRateDate->getYear(); } $this->linkList = "http://www.nbp.pl/kursy/xml/dir{$year}.txt"; } }