juxt

2020-07-12T21:44:37.191700Z

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

refset 2020-07-13T08:23:17.194100Z

the example on the docs shows:

(t/intersects? [(t/year)]
               (t/inc (t/year)))

2020-07-13T14:43:18.194300Z

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

refset 2020-07-13T15:00:18.194500Z

comparing with the reference code I posted, what happens when you add a vector in there (t/intersects? [t4] ti)

2020-07-13T17:14:49.194700Z

Not sure how to interpret this:

=> (t/intersects? [t4] ti)
nil

2020-07-13T17:46:28.194900Z

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]"})

2020-07-13T17:47:17.195100Z

I question the use of the question mark at the end of this function name 🙂

tomd 2020-07-13T17:58:01.195300Z

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

😎 1
2020-07-13T18:46:23.195500Z

@tomd Nice! Thanks for the tip!

🙂 1
refset 2020-07-12T23:48:26.191800Z

I think intersects? can do the job, but I'm not 100%