diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-24 22:28:13 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-24 22:28:13 +0200 |
commit | ac374b555accaf7a83424c241f38f997dc6a2068 (patch) | |
tree | d598692548f1daf186623bed8db62b7f77312673 | |
parent | Minor change. (diff) | |
download | calp-ac374b555accaf7a83424c241f38f997dc6a2068.tar.gz calp-ac374b555accaf7a83424c241f38f997dc6a2068.tar.xz |
Timespan-overlaps? single moment and tests.
Diffstat (limited to '')
-rw-r--r-- | module/datetime/util.scm | 7 | ||||
-rw-r--r-- | tests/datetime-util.scm | 64 |
2 files changed, 67 insertions, 4 deletions
diff --git a/module/datetime/util.scm b/module/datetime/util.scm index 1bbde87d..6b0a8411 100644 --- a/module/datetime/util.scm +++ b/module/datetime/util.scm @@ -211,6 +211,9 @@ ;; | ||s2| : |s1|| | : | || | : | || | : | || | : ;; | | : | | : | || | : | || | : | || | : |s2| ;; | | : | | : | | : | | : : | | +;; +;; Infinitely short ---+|s2| : |s1|+--- : two instants don't overlap +;; events, overlap s1 : s2 : ;; @end verbatim ;; ;; E is covered by both case A and B. @@ -226,11 +229,11 @@ (date/-time<? s2-begin s1-end)) ;; C - (and (date/-time<? s1-begin s2-begin) + (and (date/-time<=? s1-begin s2-begin) (date/-time<? s2-end s1-end)) ;; D - (and (date/-time<? s2-begin s1-begin) + (and (date/-time<=? s2-begin s1-begin) (date/-time<? s1-end s2-end)))) (define-public (add-day d) diff --git a/tests/datetime-util.scm b/tests/datetime-util.scm index 4ba432ca..80a8df5e 100644 --- a/tests/datetime-util.scm +++ b/tests/datetime-util.scm @@ -1,5 +1,5 @@ -(((datetime) date time) - ((datetime util) month-stream in-date-range?) +(((datetime) date time datetime) + ((datetime util) month-stream in-date-range? timespan-overlaps?) ((srfi srfi-41) stream->list stream-take )) @@ -24,3 +24,63 @@ (not ((in-date-range? #2020-01-01 #2020-02-29) #2018-02-02))) + + + +(test-assert "A" + (timespan-overlaps? #2020-01-01 #2020-01-10 + #2020-01-05 #2020-01-15)) + +(test-assert "A, shared start" + (timespan-overlaps? #2020-01-01 #2020-01-10 + #2020-01-01 #2020-01-15)) + +(test-assert "A, tangential" + (not (timespan-overlaps? #2020-01-01T00:00:00 #2020-01-10T00:00:00 + #2020-01-10T00:00:00 #2020-01-30T00:00:00))) + + + +(test-assert "s1 instant" + (timespan-overlaps? #2020-01-15T10:00:00 #2020-01-15T10:00:00 + #2020-01-10T00:00:00 #2020-01-30T00:00:00)) + +(test-assert "s2 instant" + (timespan-overlaps? #2020-01-10T00:00:00 #2020-01-30T00:00:00 + #2020-01-15T10:00:00 #2020-01-15T10:00:00)) + +(test-assert "s1 instant, shared start with s2" + (timespan-overlaps? #2020-01-15T10:00:00 #2020-01-15T10:00:00 + #2020-01-15T10:00:00 #2020-01-30T00:00:00)) + + +(test-assert "s1 instant, shared end with s2" + (not (timespan-overlaps? #2020-01-15T10:00:00 #2020-01-15T10:00:00 + #2020-01-10T00:00:00 #2020-01-15T10:00:00))) + +(test-assert "s2 instant, shared start with s1" + (timespan-overlaps? #2020-01-15T10:00:00 #2020-01-30T00:00:00 + #2020-01-15T10:00:00 #2020-01-15T10:00:00)) + + +(test-assert "s2 instant, shared end with s1" + (not (timespan-overlaps? #2020-01-10T00:00:00 #2020-01-15T10:00:00 + #2020-01-15T10:00:00 #2020-01-15T10:00:00))) + + +(test-assert "both instant" + (not (timespan-overlaps? #2020-01-15T10:00:00 #2020-01-15T10:00:00 + #2020-01-15T10:00:00 #2020-01-15T10:00:00))) + +(test-assert "tangential whole day" + (not (timespan-overlaps? #2020-01-01 #2020-01-02 + #2020-01-02 #2020-01-03))) + +(test-assert "B" + (timespan-overlaps? #2020-01-05 #2020-01-15 + #2020-01-01 #2020-01-10)) + + +(test-assert "E" + (timespan-overlaps? #2020-01-01 #2020-01-10 + #2020-01-01 #2020-01-10)) |