From 009515f548c0ad084ffb165c9e7aec1247ae5f9e Mon Sep 17 00:00:00 2001 From: tiemvanderdeure Date: Thu, 30 Jan 2025 15:02:49 +0100 Subject: [PATCH 1/3] use <= when finding date ranges --- src/shared.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared.jl b/src/shared.jl index 70c4825..450ca0b 100644 --- a/src/shared.jl +++ b/src/shared.jl @@ -42,7 +42,7 @@ function _format(T::Type{<:RasterDataSource}, date::TimeType) # find which bin it is in r = range(daterange...; step = datestep) - idx = searchsortedfirst(r, date) + idx = searchsortedfirst(r, date, lt = <=) # from here on just use integer math startyear = Dates.year(first(daterange)) From 0f990c284fd3c603fdf611000e485ea70df484f6 Mon Sep 17 00:00:00 2001 From: tiemvanderdeure Date: Thu, 30 Jan 2025 15:03:03 +0100 Subject: [PATCH 2/3] add a test --- test/worldclim-future.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/worldclim-future.jl b/test/worldclim-future.jl index 7394296..e4ba8e5 100644 --- a/test/worldclim-future.jl +++ b/test/worldclim-future.jl @@ -47,3 +47,12 @@ end @test isfile(date_path) end + + +@testset "WorldClim dates" begin + bioclim_name = "wc2.1_10m_bioc_MRI-ESM2-0_ssp126_2041-2060.tif" + @test rastername(WorldClim{Future{BioClim,CMIP6,MRI_ESM2_0,SSP126}}, 5; date=Date(2041), res = "10m") == + rastername(WorldClim{Future{BioClim,CMIP6,MRI_ESM2_0,SSP126}}, 5; date=Date(2060), res = "10m") == + bioclim_name + +end \ No newline at end of file From b230bfbe5b1c8c23de3c2e59815fe56f7dd3f359 Mon Sep 17 00:00:00 2001 From: tiemvanderdeure Date: Thu, 30 Jan 2025 15:03:24 +0100 Subject: [PATCH 3/3] whitespace change --- test/worldclim-future.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/worldclim-future.jl b/test/worldclim-future.jl index e4ba8e5..dddfc7c 100644 --- a/test/worldclim-future.jl +++ b/test/worldclim-future.jl @@ -53,6 +53,5 @@ end bioclim_name = "wc2.1_10m_bioc_MRI-ESM2-0_ssp126_2041-2060.tif" @test rastername(WorldClim{Future{BioClim,CMIP6,MRI_ESM2_0,SSP126}}, 5; date=Date(2041), res = "10m") == rastername(WorldClim{Future{BioClim,CMIP6,MRI_ESM2_0,SSP126}}, 5; date=Date(2060), res = "10m") == - bioclim_name - + bioclim_name end \ No newline at end of file