Fork me on GitHub
#juxt
<
2022-08-15
>
dvingo13:08:49

I had the same question, I came up with these two versions (I'm not certain they are completely correct):

(defn within?
  "Is date inside given interval (or start end)"
  ([intvl d]
   (contains? #{:starts :meets :during :finishes}
     (t.i/relation d intvl)))
  ([start end d]
   (within? (t.i/new-interval start end) d)))

(defn within2?
  "Is date inside given interval (or start end)"
  ([intvl d]
   (t/< (->date-time (t/beginning intvl)) (->date-time d) (->date-time (t/end intvl))))
  ([start end d]
   (t/< (->date-time start) (->date-time d) (->date-time end))))
->date-time takes any date/time object and casts to a date-time so you can just always pass a date-time instead and remove that

dvingo13:08:54

for -> js/Date there is t/inst again a more general cast fn:

(defn ->inst [d]
  (cond
    (date? d) (t/inst (t/at d (t/midnight)))
    (date-time? d) (t/inst d)
    (instant? d) (t/inst d)
    (time? d) (t/at (t/today) d)
    (inst? d) d
    (integer? d) (t/instant d)
    :else (throw (error "Cannot convert " (pr-str d) " to inst."))))
Note that per your domain this may not be the logic you want as dates are based on calendars, and instants are on the Universal Timeline.