This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-12
Channels
- # babashka (6)
- # beginners (23)
- # calva (27)
- # cider (1)
- # clj-kondo (23)
- # cljsrn (2)
- # clojars (4)
- # clojure (90)
- # clojure-dev (8)
- # clojure-europe (1)
- # clojure-serbia (1)
- # clojure-spec (2)
- # clojurescript (9)
- # code-reviews (7)
- # core-async (1)
- # cursive (4)
- # datomic (13)
- # emacs (2)
- # hoplon (28)
- # juxt (12)
- # leiningen (1)
- # malli (22)
- # nrepl (3)
- # off-topic (51)
- # reitit (8)
- # shadow-cljs (16)
- # spacemacs (25)
- # sql (4)
- # test-check (5)
- # tools-deps (5)
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)))
What is an ival
?
(defn intersects? [ivals interval]
(not-empty (intersection ivals [interval])))
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)
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]"})