aboutsummaryrefslogtreecommitdiff
path: root/tests/test/datetime-util.scm
blob: ca8a92410a26d903bf61e839acefd008b716637a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
;;; Commentary:
;; Tests timespan overlaps and month-streams.
;; Separate from tests/datetime.scm since
;; (datetime util) originally was its own module.
;;; Code:

(define-module (test datetime-util)
  :use-module (srfi srfi-64)
  :use-module (srfi srfi-88)
  :use-module ((datetime)
               :select (date time
                             datetime
                             month-stream
                             in-date-range?
                             timespan-overlaps?))
  :use-module ((srfi srfi-41)
               :select (stream->list stream-take)))

(test-assert
  "jan->dec"
  (stream->list
    (stream-take
      11
      (month-stream
        #2020-01-01))))

(test-assert
  "dec->jan"
  (stream->list
    (stream-take
      2
      (month-stream
        #2020-12-01))))

(test-assert
  "dec->feb"
  (stream->list
    (stream-take
      3
      (month-stream
        #2020-12-01))))

(test-assert
  "20 months"
  (stream->list
    (stream-take
      20
      (month-stream
        #2020-01-01))))

(test-equal
  "Correct months"
  (list #2020-02-01
        #2020-03-01
        #2020-04-01
        #2020-05-01
        #2020-06-01
        #2020-07-01
        #2020-08-01
        #2020-09-01
        #2020-10-01
        #2020-11-01
        #2020-12-01
        #2021-01-01)
  (stream->list
    (stream-take
      12
      (month-stream
        #2020-02-01))))

(test-assert
  "in-date-range?"
  (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))