Get the Rates object from the Provider

@param null|string $base
@param null|string $date

@return Rates
5207
public function getRateModel($base = null, $date = null) : Rates
    {
        $base = strtoupper($base);
        if (empty($base)) {
            $base = 'USD';
        }
        if (empty($date)) {
            $date = date('Y-m-d');
        }
        $this->fromCache = false;
        $api = $this->api;

        if ($this->cacheEnabled) {
            $cachekey = "cc-$api-$base-$date";

            $rates = Cache::get($cachekey);
            if (is_object($rates) and isset($rates->rates)) {
                $this->fromCache = true;
                if ($this->logEnabled) {
                    Log::debug("Got currency rates from cache: $cachekey");
                }
            }
            else {
                $rates = $this->provider->rates($base, $date);
                if (!empty($rates->rates)) {
                    if(Cache::add($cachekey, $rates, $this->cacheMinutes) and $this->logEnabled) {
                        Log::debug('Added new currency rates to cache: '.$cachekey.' for '.$this->cacheMinutes.' min.');
                    }
                }
            }
        }
        else {
            $rates = $this->provider->rates($base, $date);
        }

        if (empty($rates->rates)) {
            Log::warning("$rates->error -> $rates->url");
        }

        return $rates;
    }
399294
public function floatDiffInMinutes($date = null, $absolute = true)
    {
        return $this->floatDiffInSeconds($date, $absolute) / static::SECONDS_PER_MINUTE;
    }
719804
protected function getBaseRates(string $currency, string $date)
    {
        $this->currency = $currency;
        $this->date = $date;

        if (isset($this->baseRates[strtoupper($currency)][$date])) {

            return $this->baseRates[strtoupper($currency)][$date];
        }

        return null;
    }
593090
public function getRates(\DateTime $date = null)
    {
        if (null === $date) {
            $date = new \DateTime();
        }

        // Pokud je pozadan kurz pro dnesni den a jeste nebylo 14:15 zverejnim vcerejsi kurz
        if ($date->format('Hi') < 1415) {
            $date->modify('-1 day');
        }

        $cachedFileName = $date->format('Ymd').'.php';

        if (!is_dir($this->cacheDir)) {
            mkdir($this->cacheDir);
        }

        $cachedFile = $this->cacheDir.'/cnb_'.$cachedFileName;

        if (!is_file($cachedFile)) {
            $url = sprintf(self::API_URL, urlencode($date->format('d.m.Y')));
            $file = explode("\n", file_get_contents($url));

            $rates = [];

            foreach ($file as $index => $line) {
                // Datum a hlavicku souboru preskocime
                if ($index < 2) {
                    continue;
                }
                // Pokud je radek prazdny
                if (empty($line)) {
                    continue;
                }
                $rate = explode('|', $line);

                $rates[$rate[3]] = new Rate(
                    $date,
                    $rate[3],
                    $rate[0],
                    $rate[1],
                    Lib::toNumber($rate[2]),
                    Lib::toNumber($rate[4])
                );
            }
            file_put_contents($cachedFile, serialize($rates));
        } else {
            $rates = unserialize(file_get_contents($cachedFile));
        }

        // Prevedeni do objektu Rates pro lepsi pristup v sablonach
        return new Rates($date, $rates);
    }
836486
public function evaluateExclusions($date = null)
    {
        if (!$date) {
            $date = clone $this->now;
        }
        // Check dates of exclusion (if there are any).
        $jsonHelper       = new JSONHelper();
        $exclusionsString = $this->contactClient->getScheduleExclusions();
        $exclusions       = $jsonHelper->decodeArray($exclusionsString, 'ScheduleExclusions');
        if ($exclusions) {
            // Fastest way to compare dates is by string.
            $todaysDateString = $date->format('Y-m-d');
            foreach ($exclusions as $exclusion) {
                if (!empty($exclusion->value)) {
                    $dateString   = trim(str_ireplace('yyyy-', '', $exclusion->value));
                    $segments     = explode('-', $dateString);
                    $segmentCount = count($segments);
                    if (3 == $segmentCount) {
                        $year  = !empty($segments[0]) ? str_pad(
                            $segments[0],
                            4,
                            '0',
                            STR_PAD_LEFT
                        ) : $date->format(
                            'Y'
                        );
                        $month = !empty($segments[1]) ? str_pad(
                            $segments[1],
                            2,
                            '0',
                            STR_PAD_LEFT
                        ) : $date->format('m');
                        $day   = !empty($segments[2]) ? str_pad(
                            $segments[2],
                            2,
                            '0',
                            STR_PAD_LEFT
                        ) : $date->format('d');
                    } elseif (2 == $segmentCount) {
                        $year  = $date->format('Y');
                        $month = !empty($segments[0]) ? str_pad(
                            $segments[0],
                            2,
                            '0',
                            STR_PAD_LEFT
                        ) : $date->format('m');
                        $day   = !empty($segments[1]) ? str_pad(
                            $segments[1],
                            2,
                            '0',
                            STR_PAD_LEFT
                        ) : $date->format('d');
                    } else {
                        continue;
                    }
                    $dateString = $year.'-'.$month.'-'.$day;
                    if ($dateString == $todaysDateString) {
                        throw new ContactClientException(
                            'This contact client does not allow contacts on the date '.$dateString.'.',
                            0,
                            null,
                            Stat::TYPE_SCHEDULE,
                            false
                        );
                    }
                }
            }
        }

        return $this;
    }
547924
def rate(self, from_currency, to_currency, date):
        """"""
        return (1 / self.backend.get_rate(from_currency, date)) * self.backend.get_rate(
            to_currency, date
        )
921811
public function days($date = null)
	{
		return is_string($date) ? (new \DateTime($date, self::$utc))->diff($this->date)->days : $date->diff($this->date)->days;
	}
919170
public function floatDiffInSeconds($date = null, $absolute = true)
    {
        return $this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_SECOND;
    }
152185
protected function getLogOrFail($date)
    {
        $log = null;

        try {
            $log = $this->logViewer->get($date);
        }
        catch (LogNotFoundException $e) {
            abort(404, $e->getMessage());
        }

        return $log;
    }
833682
public function setDateFrom($date = null)
    {
        $date = $this->resolveCarbon($date);

        return $this->setDate($date->year, $date->month, $date->day);
    }
678063
private function convert($input) : Rates
    {
        $rates = new Rates();
        $rates->timestamp = time();
        $rates->date = $this->date;
        $rates->base = 'EUR';
        $rates->rates = [];
        $rates->url = $this->url;

        $data = json_decode($input, true);

        if (!empty($data)) {
            if (!empty($data['rates'])) {
                $rates->extra['fixer_date'] = $data['date'] ?? null;
                foreach ($data['rates'] as $key => $row) {
                    $rates->rates[$key] = $row;
                }
                //add 1:1 conversion rate from base for testing
                $rates->rates[$data['base']] = 1;
            }
        }
        else {
            $rates->error = "No data in response from Fixer.io";
        }

        return $rates;
    }
723750
public static function sunday($date = null)
    {
        if ($date) {
            return Carbon::parse($date)->startOfWeek(Carbon::SUNDAY);
        }

        return Carbon::now()->startOfWeek(Carbon::SUNDAY);
    }
1335160
public function rates(string $currency, string $date) : Rates
    {
        $rates = $this->getBaseRates($currency, $date);
        if (empty($rates)) {
            $rates = $this->convert($this->download($date));
            if ($currency !== 'EUR') {
                //Set USD base rate
                $this->setBaseRates($rates->convertBaseRatesToUSD());

                if ($currency !== 'USD') {
                    $rates = $rates->convertBaseRateToCurrency($currency);
                    $this->setBaseRates($rates);
                }
            }
            else {
                $this->setBaseRates($rates);
            }
        }

        return $rates;
    }
551313
public function get($date, $default = null)
    {
        if (!$this->has($date)) {
            throw new Exception('Log not found in this date [' . $date . ']');
        }

        return parent::get($date, $default);
    }
281695
protected function frontendToInternal($date)
    {
        if (!$date) {
            return null;
        }
        $fromFormatter = $this->getFrontendFormatter();
        $toFormatter = $this->getInternalFormatter();
        $timestamp = $fromFormatter->parse($date);
        if ($timestamp === false) {
            return null;
        }
        return $toFormatter->format($timestamp) ?: null;
    }
107324
final public static function asUtcSql($date)
    {
        if (!empty($date)) {
            if ($date instanceof \DateTimeInterface) {
                return $date->setTimezone(self::tzUtc())->format('Y-m-d H:i:s');
            } else {
                return self::asDateTime($date, "UTC")->format('Y-m-d H:i:s');
            }
        } else {
            return null;
        }
    }
534915
def get_exchange_rates(self, base, targets=None):
        """"""
        if targets is None:
            targets = get_available_currencies()

        return {t: self.get_exchange_rate(base, t, raise_errors=False) for t in targets}