Skip to content

Commit 310980f

Browse files
mileslucasabhro
andauthored
add special case for multiplication with ranges (#67)
* add special case for multiplication with ranges * bump project to 0.7.1 * Bump version 0.7.2 --------- Co-authored-by: abhro <[email protected]>
1 parent 4a0001c commit 310980f

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AstroTime"
22
uuid = "c61b5328-d09d-5e37-a9a8-0eb41c39009c"
3-
version = "0.7.1"
3+
version = "0.7.2"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/Periods.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ Base.:*(dt::Number, unit::TimeUnit) = AstroPeriod(unit, dt)
153153
Base.:*(unit::TimeUnit, dt::Number) = AstroPeriod(unit, dt)
154154
Base.:*(A::TimeUnit, B::AbstractArray) = broadcast(*, A, B)
155155
Base.:*(A::AbstractArray, B::TimeUnit) = broadcast(*, A, B)
156+
# handle ranges in lazy fashion
157+
Base.:*(B::TimeUnit, R::AbstractRange) = first(R) * B:step(R) * B:last(R) * B
158+
Base.:*(R::AbstractRange, B::TimeUnit) = first(R) * B:step(R) * B:last(R) * B
156159

157160
Base.:-(p::AstroPeriod) = AstroPeriod(unit(p), -p.second, -p.fraction, -p.error)
158161

test/periods.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,9 @@
9898
@test string(1days) == "1.0 days"
9999
@test string(1years) == "1.0 years"
100100
@test string(1centuries) == "1.0 centuries"
101+
102+
# lazy ranges (#65)
103+
@test (1:3) * seconds === seconds * (1:3)
104+
@test (1:3) * seconds isa AbstractRange
101105
end
102106

0 commit comments

Comments
 (0)