Given a tick interval and a time, is there an existing function to test if the time is within the interval? Given I couldn't find one, here is what I wrote (not claiming it is any good):
(defn within?
[i time]
(and (t/>= time (t/beginning i))
(t/>= (t/end i) time)))
the example on the docs shows:
(t/intersects? [(t/year)]
(t/inc (t/year)))
Doesn't seem like intersects?
works with a non-interval....
=> t4
#time/zoned-date-time "2020-07-04T00:00-07:00[US/Pacific]"
=> ti
#:tick{:beginning #time/zoned-date-time "2020-07-04T00:00-07:00[US/Pacific]", :end #time/zoned-date-time "2020-07-05T00:00-07:00[US/Pacific]"}
=> (t/intersects? t4 ti)
Execution error (UnsupportedOperationException) at tick.interval/assert-proper-head (interval.cljc:427).
nth not supported on this type: ZonedDateTime
comparing with the reference code I posted, what happens when you add a vector in there (t/intersects? [t4] ti)
Not sure how to interpret this:
=> (t/intersects? [t4] ti)
nil
Also:
=> (t/intersects? [ti] ti)
(#:tick{:beginning #time/zoned-date-time "2020-07-04T00:00-07:00[US/Pacific]", :end #time/zoned-date-time "2020-07-05T00:00-07:00[US/Pacific]"})
I question the use of the question mark at the end of this function name 🙂
The tick versions of >=
etc are variadic just like clojure.core's, so your within?
function could just be:
(t/<= (t/beginning i) time (t/end i))
I'm not sure there is a shorter version than that@tomd Nice! Thanks for the tip!
I think intersects?
can do the job, but I'm not 100%