Fork me on GitHub
#juxt
<
2021-09-17
>
dcj00:09:08

If I have a time, and an interval, is there an existing function to determine if that time resides within (is contained by) the interval? Are tick interval bounds inclusive, or exclusive, or some mixture? For example org.threeten.extra.Interval

An interval represents the time on the time-line between two Instants. 
The class stores the start and end instants, with the start inclusive and the end exclusive. 
The end instant is always greater than or equal to the start instant.

dominicm07:09:09

@dcj maybe coincident? works for your use-case too?

dcj16:09:02

WRT "Are tick interval bounds inclusive or exclusive?" According to the docs:

(= (t.i/new-interval (t/date-time "2000-01-01T00:00")
                   (t/date-time "2001-01-01T00:00"))
   (t.i/bounds (t/year 2000))
   {:tick/beginning (t/date-time "2000-01-01T00:00")
    :tick/end (t/date-time "2001-01-01T00:00")})
And
(t/in (t/bounds (t/today)) "US/Pacific")
#:tick{:beginning
       #time/zoned-date-time "2021-09-17T00:00-07:00[US/Pacific]",
       :end
       #time/zoned-date-time "2021-09-18T00:00-07:00[US/Pacific]"}
This leads me to conclude that the :tick/beginning bound is inclusive, and :tick/end is exclusive, anyone disagree???

dcj16:09:25

WRT "how to determine if a time resides within (is contained by) an interval", seems like this would work:

(defn contained-by-interval?
  [t {:keys [tick/beginning tick/end] :as i}]
  (and (t/<= beginning t) (t/< t end)))

alexdavis16:09:44

The tick docs have been temporarily taken down as they are out of date and the place they were being hosted has some issues. You can access up to date ones here for now (or of course see the repo) https://festive-haibt-f050e6.netlify.app/

👍 2