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" 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