Skip to content

Commit

Permalink
Merge pull request #11 from Deduction42/DEV
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RGonTheNoble authored Nov 14, 2024
2 parents be07a8b + b2d49f7 commit 67eb766
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TimeRecords"
uuid = "b543fe20-4c68-4b5f-af79-4641a0d39826"
authors = ["Ruben Gonzalez <[email protected]> and contributors"]
version = "1.3.0"
version = "1.3.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
8 changes: 8 additions & 0 deletions src/find.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ findinner(ts::AbstractTimeSeries, Δt::TimeInterval, indhint::Integer=firstindex
Finds the indices of the time series (ts) where Δt[begin] <= ts.t <= Δt[end])
"""
function findinner(ts::AbstractTimeSeries, Δt::TimeInterval, indhint=nothing)
if isempty(ts)
return 1:0
end

bndL = findbounds(ts, Δt[begin], indhint)
lb = ifelse(_equal_timestamp(ts, bndL[1], Δt[begin]), bndL[1], bndL[2])

Expand Down Expand Up @@ -56,6 +60,10 @@ Finds the indices of the TimeSeries ts that surround the time interval Δt,
If Δt is outside the time range both results will be the nearest index
"""
function findouter(ts::AbstractTimeSeries, Δt::TimeInterval, indhint=nothing)
if isempty(ts)
return 1:0
end

bndL = clampedbounds(ts, Δt[begin], indhint)
lb = ifelse(_equal_timestamp(ts, bndL[2], Δt[begin]), bndL[2], bndL[1])

Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using Dates
# Test time series
ts = TimeSeries{Float64}(1:5, 1:5)
t = [1.5, 2.5, 3.5]
tse = TimeSeries{Float64}()

#Test extrapolation/interpolation
@test values(interpolate(ts, t, order=0)) [1, 2, 3]
Expand Down Expand Up @@ -82,6 +83,12 @@ using Dates
@test getouter(ts, dt_middle+0.1) == ts[2:5]
@test viewouter(ts, dt_middle+0.1) == ts[2:5]

@test findinner(tse, dt_middle) == 1:0
@test findouter(tse, dt_middle) == 1:0
@test getinner(tse, dt_middle) == tse[1:0]
@test getouter(tse, dt_middle) == tse[1:0]


@test keeplatest!(TimeSeries(1:5,1:5), 4) == TimeSeries(4:5, 4:5)
@test keeplatest!(TimeSeries(1:5,1:5), 2.5) == TimeSeries(2:5, 2:5)
@test keeplatest!(TimeSeries(1:5,1:5)) == TimeSeries([5],[5])
Expand Down

2 comments on commit 67eb766

@RGonTheNoble
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Now supports calling the following functions on empty timeseries: findinner, findouter, getinner, getouter

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119425

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.1 -m "<description of version>" 67eb766d5a247546264fe62d0cedb25e3c3b19c8
git push origin v1.3.1

Please sign in to comment.