Skip to content

Commit

Permalink
Merge pull request #194 from almegren/master
Browse files Browse the repository at this point in the history
Make interval/concur handle three or more adjecent intervals
  • Loading branch information
henryw374 authored Nov 22, 2023
2 parents 1d0b7f1 + 3f587fa commit 6c19799
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/tick/alpha/interval.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,14 @@
representing the interval of time the given intervals are
concurrent."
([x y]
(case (relation x y)
:overlaps (slice x (t/beginning y) (t/end x))
:overlapped-by (slice x (t/beginning x) (t/end y))
(:starts :finishes :during :equals) x
(:started-by :finished-by :contains) (slice x (t/beginning y) (t/end y))
nil))
(if (or (nil? x) (nil? y))
nil
(case (relation x y)
:overlaps (slice x (t/beginning y) (t/end x))
:overlapped-by (slice x (t/beginning x) (t/end y))
(:starts :finishes :during :equals) x
(:started-by :finished-by :contains) (slice x (t/beginning y) (t/end y))
nil)))
([x y & args]
(reduce concur (concur x y) args)))

Expand Down
24 changes: 23 additions & 1 deletion test/tick/alpha/interval_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,29 @@
(ti/new-interval (instants 1) (instants 3))
(ti/concur
(ti/new-interval (instants 1) (instants 3))
(ti/new-interval (instants 0) (instants 3))))))
(ti/new-interval (instants 0) (instants 3)))))

(is
(=
(ti/new-interval (instants 1) (instants 2))
(ti/concur
(ti/new-interval (instants 1) (instants 3))
(ti/new-interval (instants 1) (instants 2))
(ti/new-interval (instants 0) (instants 2)))))

(is
(nil?
(ti/concur
(ti/new-interval (instants 1) (instants 2))
(ti/new-interval (instants 2) (instants 3))
(ti/new-interval (instants 0) (instants 2)))))

(is
(nil?
(ti/concur
(ti/new-interval (instants 0) (instants 1))
(ti/new-interval (instants 1) (instants 2))
(ti/new-interval (instants 2) (instants 3))))))

;; Sequence tests

Expand Down

0 comments on commit 6c19799

Please sign in to comment.