This commit is contained in:
Hakan Ensari 2020-05-02 15:18:52 +01:00
parent ec302e726c
commit 2e83b9d50d
3 changed files with 8 additions and 8 deletions

View File

@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
### Changed ### Changed
- Sample weekly when querying over 365 days - Sample weekly when querying over a year
- Bump PostgreSQL to 12 - Bump PostgreSQL to 12
## 1.0.0 - 2020-01-02 ## 1.0.0 - 2020-01-02

View File

@ -17,7 +17,7 @@ class Currency < Sequel::Model(Day.currencies)
def between(interval) def between(interval)
case interval.last - interval.first case interval.last - interval.first
when 91.. then super.sample('week') when 366.. then super.sample('week')
else super else super
end end
end end

View File

@ -16,14 +16,14 @@ describe Currency do
Date.parse('2010-01-01') Date.parse('2010-01-01')
end end
it 'returns everything up to 90 days' do it 'returns everything up to a year' do
interval = day..day + 90 interval = day..day + 365
Currency.between(interval).map(:date).uniq.count.must_be :>, 30 Currency.between(interval).map(:date).uniq.count.must_be :>, 52
end end
it 'samples weekly over 90 days' do it 'samples weekly over a year' do
interval = day..day + 365 interval = day..day + 366
Currency.between(interval).map(:date).uniq.count.must_be :<=, 52 Currency.between(interval).map(:date).uniq.count.must_be :<, 54
end end
it 'sorts by date' do it 'sorts by date' do