Commit3e751f0fRecorded29 Mar 2026Repositorysigil-wise

Import date utilities from (sigil time) instead of defining locally

Message

Remove local copies of parse-iso-date, format-iso-date, days-in-month, add-days, and date-compare. These are now provided by (sigil time) in sigil-stdlib. wise-date-windows is kept as it's Wise-specific.

Changed
 src/wise.sgl | 82 +++-------------------------------------------------------------------------------
 1 file changed, 3 insertions(+), 79 deletions(-)
Diff
src/wise.sglmodified
@@ -10,7 +10,9 @@
10
(sigil struct)
11
(sigil json)
12
(only (sigil http) url-encode-value build-query-string)
13
(sigil http client))
+13
(sigil http client)
+14
(only (sigil time) parse-iso-date format-iso-date
+15
days-in-month add-days date-compare))
16
17
(export ;; Client
18
wise-client
@@ -165,84 +167,6 @@
167
;;; Maximum number of days per statement request (Wise limit).
168
(define wise-max-window-days 469)
169
168
;;; Parse an ISO 8601 date string "YYYY-MM-DDTHH:MM:SSZ" into a list
169
;;; of (year month day hour minute second).
170
(define (parse-iso-date s)
171
(list (string->number (substring s 0 4))
172
(string->number (substring s 5 7))
173
(string->number (substring s 8 10))
174
(if (> (string-length s) 10)
175
(string->number (substring s 11 13))
176
0)
177
(if (> (string-length s) 13)
178
(string->number (substring s 14 16))
179
0)
180
(if (> (string-length s) 16)
181
(string->number (substring s 17 19))
182
0)))
183
184
;;; Format a date list back to ISO 8601 UTC string.
185
(define (format-iso-date parts)
186
(let ((year (list-ref parts 0))
187
(month (list-ref parts 1))
188
(day (list-ref parts 2))
189
(hour (list-ref parts 3))
190
(minute (list-ref parts 4))
191
(second (list-ref parts 5)))
192
(string-append
193
(number->string year) "-"
194
(if (< month 10) "0" "") (number->string month) "-"
195
(if (< day 10) "0" "") (number->string day) "T"
196
(if (< hour 10) "0" "") (number->string hour) ":"
197
(if (< minute 10) "0" "") (number->string minute) ":"
198
(if (< second 10) "0" "") (number->string second) "Z")))
199
200
;;; Days in a given month (handles leap years).
201
(define (days-in-month year month)
202
(cond
203
((memv month '(1 3 5 7 8 10 12)) 31)
204
((memv month '(4 6 9 11)) 30)
205
((= month 2)
206
(if (and (= (modulo year 4) 0)
207
(or (not (= (modulo year 100) 0))
208
(= (modulo year 400) 0)))
209
29 28))
210
(else 30)))
211
212
;;; Add a number of days to a date list, returning a new date list.
213
(define (add-days parts n)
214
(let ((year (list-ref parts 0))
215
(month (list-ref parts 1))
216
(day (list-ref parts 2))
217
(hour (list-ref parts 3))
218
(minute (list-ref parts 4))
219
(second (list-ref parts 5)))
220
(let loop ((y year) (m month) (d (+ day n)))
221
(let ((dim (days-in-month y m)))
222
(cond
223
((> d dim)
224
(let ((new-m (+ m 1)))
225
(if (> new-m 12)
226
(loop (+ y 1) 1 (- d dim))
227
(loop y new-m (- d dim)))))
228
((< d 1)
229
(let ((prev-m (- m 1)))
230
(if (< prev-m 1)
231
(let ((py (- y 1)))
232
(loop py 12 (+ d (days-in-month py 12))))
233
(loop y prev-m (+ d (days-in-month y prev-m))))))
234
(else
235
(list y m d hour minute second)))))))
236
237
;;; Compare two date lists. Returns -1, 0, or 1.
238
(define (date-compare a b)
239
(let loop ((as a) (bs b))
240
(cond
241
((null? as) 0)
242
((< (car as) (car bs)) -1)
243
((> (car as) (car bs)) 1)
244
(else (loop (cdr as) (cdr bs))))))
245
170
;;; Split a date range into windows of at most wise-max-window-days.
171
;;; Returns a list of (start-iso . end-iso) pairs.
172
(define (wise-date-windows start-iso end-iso)