From e1ba115fb6140bf971cb243cf7967355faa6af29 Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Mon, 25 Oct 2021 16:37:29 -1000 Subject: [PATCH 1/2] add special case for multiplication with ranges --- src/Periods.jl | 3 +++ test/periods.jl | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/Periods.jl b/src/Periods.jl index caf939e..985d944 100644 --- a/src/Periods.jl +++ b/src/Periods.jl @@ -153,6 +153,9 @@ Base.:*(dt::Number, unit::TimeUnit) = AstroPeriod(unit, dt) Base.:*(unit::TimeUnit, dt::Number) = AstroPeriod(unit, dt) Base.:*(A::TimeUnit, B::AbstractArray) = broadcast(*, A, B) Base.:*(A::AbstractArray, B::TimeUnit) = broadcast(*, A, B) +# handle ranges in lazy fashion +Base.:*(B::TimeUnit, R::AbstractRange) = first(R) * B:step(R) * B:last(R) * B +Base.:*(R::AbstractRange, B::TimeUnit) = first(R) * B:step(R) * B:last(R) * B Base.:-(p::AstroPeriod) = AstroPeriod(unit(p), -p.second, -p.fraction, -p.error) diff --git a/test/periods.jl b/test/periods.jl index bd133a3..40aff78 100644 --- a/test/periods.jl +++ b/test/periods.jl @@ -98,5 +98,9 @@ @test string(1days) == "1.0 days" @test string(1years) == "1.0 years" @test string(1centuries) == "1.0 centuries" + + # lazy ranges (#65) + @test (1:3) * seconds === seconds * (1:3) + @test (1:3) * seconds isa AbstractRange end From c34c7fa3f89c2c1b88f84ccc93c481d3f50ef29e Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Mon, 25 Oct 2021 16:37:44 -1000 Subject: [PATCH 2/2] bump project to 0.7.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index de0b3df..1cd840a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "AstroTime" uuid = "c61b5328-d09d-5e37-a9a8-0eb41c39009c" -version = "0.7.0" +version = "0.7.1" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"