crocodile2u / ecb-rates
v1.1.0
2020-11-05 13:04 UTC
Requires (Dev)
- phpunit/phpunit: ^9.4
This package is auto-updated.
Last update: 2024-09-05 20:46:04 UTC
README
需求
- ZIP php 扩展 (
"ext-zip": "*"
) - JSON php 扩展 (
"ext-json": "*"
)
安装
composer require crocodile2u/ecb-rates
使用
$provider = new \ECBRates\ExchangeRateProvider($this->createRatesIterator());
// fetch latest available rates, either for today or (which is more likely) for yesterday
$latest = $provider->at(new \DateTime("now"));
// fetch latest rates excluding today, thus making sure that
// throughout of today we're operating with yesterday rates
$previous = $provider->atPreviousBusinessDay(new \DateTime("now"));
$historical = $provider->at(new \DateTime("2019-02-01"));
方法 at()
和 atPreviousBusinessDay()
都返回一个具有以下方法的 RateSet
对象
date()
- 返回有效日期的字符串表示形式 (Y-m-d),该日期对应于此 RateSetrate(string $symbol)
- 返回 $symbol 的浮点利率或找不到时返回 NULLhas(string $symbol)
- 返回 bool,表示 $symbol 的利率是否存在于本集中all()
- 以关联数组的形式返回本集中的所有利率 (string symbol => float rate)count()
- 返回本集中利率的数量