aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-02-13 22:21:44 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-03-30 03:39:16 +0200
commit8d4e11b912e44a7ad135aa7695ab3a10d9d3a26e (patch)
tree0c4f1bcf944b3795ada9bc1c84137326f30be97b
parentHandle XML entities slightly better in user-additions.js. (diff)
downloadcalp-8d4e11b912e44a7ad135aa7695ab3a10d9d3a26e.tar.gz
calp-8d4e11b912e44a7ad135aa7695ab3a10d9d3a26e.tar.xz
Remove parse-time from (datetime timespec).
-rw-r--r--module/datetime.scm5
-rw-r--r--module/datetime/timespec.scm14
2 files changed, 8 insertions, 11 deletions
diff --git a/module/datetime.scm b/module/datetime.scm
index 8cffb755..18c965ff 100644
--- a/module/datetime.scm
+++ b/module/datetime.scm
@@ -675,6 +675,11 @@ Returns -1 on failure"
[else dt]))
(cond [(null? str)
+ ;; TODO should this be considered an error?
+ ;; Should it be toggleable through a flag.
+ ;; It's sometimes useful to allow it, since it allows optional
+ ;; trailing fields, but sometimes useful to disallow it, since
+ ;; it gives a better check that the data is valid
;; ((@ (hnh util exceptions) warning)
;; "Premature end of string, still got fmt = ~s"
;; fmt)
diff --git a/module/datetime/timespec.scm b/module/datetime/timespec.scm
index 712ff327..d3a84671 100644
--- a/module/datetime/timespec.scm
+++ b/module/datetime/timespec.scm
@@ -64,15 +64,6 @@
specs))
-(define (parse-time string)
- (apply (lambda* (hour optional: (minute "0") (second "0"))
- (time hour: (string->number hour)
- minute: (string->number minute)
- ;; discard sub-seconds
- second: (string->number (car (string-split second #\.)))))
- (string-split string #\:)))
-
-
(define*-public (parse-time-spec
string optional: (suffixes '(#\s #\w #\u #\g #\z)))
(let* ((type string
@@ -81,11 +72,12 @@
(values (string-ref string idx)
(substring string 0 idx)))]
[else (values #\w string)])))
+ ;; Note that string->time allows a longer format than the input
(cond [(string=? "-" string)
(make-timespec (time) '+ type)]
[(string-prefix? "-" string)
- (make-timespec (parse-time (string-drop string 1))
+ (make-timespec (string->time (string-drop string 1) "~H:~M:~S")
'- type)]
[else
- (make-timespec (parse-time string)
+ (make-timespec (string->time string "~H:~M:~S")
'+ type)])))