Add time_slots and TimeWindow for issue #481#553
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #553 +/- ##
==========================================
+ Coverage 85.44% 86.50% +1.06%
==========================================
Files 11 13 +2
Lines 625 919 +294
==========================================
+ Hits 534 795 +261
- Misses 91 124 +33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b490941 to
e7bd27b
Compare
|
I forgot to mention I added the following tests to make sure the negative inputs are handled Error thrown: julia> time_slots(now(), now()+Day(1), Minute(-1))
ERROR: ArgumentError: interval must be positive, got -1 minute
Stacktrace:
[1] #time_slots#25
@ C:\Users\RadhaKunjBalram\Documents\open source julia\TimeSeries.jl\src\split.jl:80 [inlined]
[2] time_slots(start::DateTime, stop::DateTime, interval::Minute)
@ TimeSeries C:\Users\RadhaKunjBalram\Documents\open source julia\TimeSeries.jl\src\split.jl:71
[3] top-level scope
@ REPL[4]:1julia> time_slots(
DateTime(2023, 1, 1), DateTime(2023, 1, 2), Day(-1), from=Time(9), to=Time(17)
)
ERROR: ArgumentError: interval must be positive, got -1 day
Stacktrace:
[1] #time_slots#25
@ C:\Users\RadhaKunjBalram\Documents\open source julia\TimeSeries.jl\src\split.jl:80 [inlined]
[2] top-level scope
@ REPL[2]:1
julia> julia> rng = DateTime(2023, 1, 2):Day(-1):DateTime(2023, 1, 1)
DateTime("2023-01-02T00:00:00"):Day(-1):DateTime("2023-01-01T00:00:00")
julia> time_slots(rng)
ERROR: ArgumentError: interval must be positive, got -1 day
Stacktrace:
[1] #time_slots#26
@ C:\Users\RadhaKunjBalram\Documents\open source julia\TimeSeries.jl\src\split.jl:98 [inlined]
[2] time_slots(range::StepRange{DateTime, Day})
@ TimeSeries C:\Users\RadhaKunjBalram\Documents\open source julia\TimeSeries.jl\src\split.jl:94
[3] top-level scope
@ REPL[6]:1
julia> |
0bcd9ec to
ef88daa
Compare
03b786b to
207c0d0
Compare
207c0d0 to
09dc1ab
Compare
| function time_slots( | ||
| start::T, stop::T, interval::Period; from::Time=Time(0, 0), to::Time=Time(23, 59) | ||
| ) where {T<:TimeType} |
There was a problem hiding this comment.
| function time_slots( | |
| start::T, stop::T, interval::Period; from::Time=Time(0, 0), to::Time=Time(23, 59) | |
| ) where {T<:TimeType} | |
| function time_slots( | |
| start::T, stop::T, interval::P; from::Time=Time(0, 0), to::Time=Time(23, 59) | |
| ) where {T<:TimeType,P<:Period} |
then, also use those type variables in return?
| return TimeSlot{eltype(range),typeof(step(range))}( | ||
| range.start, range.stop, step(range), from, to | ||
| ) |
There was a problem hiding this comment.
I'm not sure about the current behaviour of compiler, is this consider type stable or not, if we use eltype(..) and typeof(..) in return statement. 🤔
type stable is preferred, still fine if not.
|
I'm still thinking about the possibility to support negative interval,
|
5aa4d17 to
06e45d5
Compare
|
ah, I think we could keep current implementation for the negative interval. |
Sure!, Let me do this real quick. |
06e45d5 to
314798a
Compare
314798a to
bac168f
Compare
|
Thanks for your contributions! |
Implements the API proposed in #481.
time_slots(start, stop, interval; from, to)— generates aTimeArrayof timestamps within a daily time windowtime_slots(range; from, to)— same, accepts aStepRange{DateTime}directlywhen(ta, time_slots(; from, to))— filters an existingTimeArrayby time-of-day via the newTimeWindowtypeCloses #481