From 8d4e11b912e44a7ad135aa7695ab3a10d9d3a26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 13 Feb 2022 22:21:44 +0100 Subject: Remove parse-time from (datetime timespec). --- module/datetime.scm | 5 +++++ module/datetime/timespec.scm | 14 +++----------- 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)]))) -- cgit v1.2.3