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"; } }
public static function anio($fecha) { $fecha = isset($fecha) && $fecha !== '' ? $fecha : ''; $dato = new Moment($fecha); return $dato->getYear(); }