Back
ITimeSpan (clj)
(source)protocol
Examples
tick
(ns tick.api-test
(:require
[clojure.test
:refer [deftest is testing run-tests]
:refer-macros [deftest is testing run-tests]]
[tick.core :as t]
[tick.locale-en-us]
[tick.protocols :as p]
[cljc.java-time.clock]
[cljc.java-time.instant]
[cljc.java-time.day-of-week]
[cljc.java-time.month]
[cljc.java-time.year]
#?@(:cljs [[java.time :refer [Instant]]]))
#?(:clj
(:import [java.time Instant])))
(extend-protocol p/ITimeSpan
; as required by some tests in this ns
Instant
(beginning [i] i)
(end [i] i))
tick
(ns tick.alpha.interval-test
(:require
[clojure.spec.alpha :as s]
[tick.core :as t]
[tick.protocols :as p]
[clojure.test
:refer [deftest is testing run-tests]
:refer-macros [deftest is testing run-tests]]
[tick.alpha.interval :as ti]
#?@(:cljs [[java.time :refer [Instant LocalDateTime LocalTime]]]))
#?(:clj
(:import [java.time LocalDateTime Instant LocalTime])))
(extend-protocol p/ITimeSpan
; as required by some tests in this ns
Instant
(beginning [i] i)
(end [i] i)
LocalDateTime
(beginning [i] i)
(end [i] i))
;; Can we disturb?
(deftest cannot-disturb-test
(extend-protocol p/ITimeSpan
LocalTime
(beginning [i] i)
(end [i] i))
(let
[disturb-interval [(ti/new-interval (t/time "07:00") (t/time "22:00"))]
no-disturb-interval (ti/complement disturb-interval)
can-disturb? (fn [t] (not (some #(t/coincident? % t) no-disturb-interval)))
]
(is (not (can-disturb? (t/time "03:00"))))
(is (not (can-disturb? (t/time "07:00"))))
(is (can-disturb? (t/time "07:01")))
(is (can-disturb? (t/time "12:00")))
(is (can-disturb? (t/time "21:59")))
(is (not (can-disturb? (t/time "22:00"))))
(is (not (can-disturb? (t/time "00:00"))))))