diff options
Diffstat (limited to 'module/datetime')
-rw-r--r-- | module/datetime/timespec.scm | 14 | ||||
-rw-r--r-- | module/datetime/zic.scm | 32 |
2 files changed, 27 insertions, 19 deletions
diff --git a/module/datetime/timespec.scm b/module/datetime/timespec.scm index ea29a423..099634b6 100644 --- a/module/datetime/timespec.scm +++ b/module/datetime/timespec.scm @@ -65,15 +65,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 @@ -82,11 +73,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)]))) diff --git a/module/datetime/zic.scm b/module/datetime/zic.scm index 0362ec99..e2600d4f 100644 --- a/module/datetime/zic.scm +++ b/module/datetime/zic.scm @@ -92,14 +92,14 @@ ;; @end example (define-public (get-zone zoneinfo name) (or (hash-ref (zoneinfo-zones zoneinfo) name) - (error "No zone ~a" name))) + (scm-error 'misc-error "get-zone" "No zone ~a" (list name) #f))) ;; @example ;; (get-rule zoneinfo 'EU) ;; @end example (define-public (get-rule zoneinfo name) (or (hashq-ref (zoneinfo-rules zoneinfo) name) - (error "No rule ~a" name))) + (scm-error 'misc-error "get-rule" "No rule ~a" (list name) #f))) @@ -119,7 +119,9 @@ [(string-prefix? name "October") 10] [(string-prefix? name "November") 11] [(string-prefix? name "December") 12] - [else (error "Unknown month" name)])) + [else (scm-error 'misc-error "month-name->number" + "Unknown month ~s" (list name) + #f)])) (define (string->weekday name) @@ -131,7 +133,9 @@ [(string-prefix? name "Friday") fri] [(string-prefix? name "Saturday") sat] [(string-prefix? name "Sunday") sun] - [else (error "Unknown week day" name)])) + [else (scm-error 'misc-error "string->weekday" + "Unknown week day ~s" + (list name) #f)])) (define (parse-from str) @@ -259,8 +263,10 @@ ;; NOTE an earlier version of the code the parsers for those. ;; They were removed since they were unused, uneeded, and was ;; technical dept. - (error (_ "Invalid key ~a. Note that leap seconds and -expries rules aren't yet implemented.") type)] + (scm-error 'misc-error "parse-zic-file" + (_ "Invalid key ~s. Note that leap seconds and expries rules aren't yet implemented.") + (list type) + #f)] ))])))))) @@ -357,7 +363,9 @@ expries rules aren't yet implemented.") type)] until: (let ((to (rule-to rule))) (case to ((maximum) #f) - ((minimum) (error (_ "Check your input"))) + ((minimum) (scm-error 'misc-error "rule->rrule" + (_ "Check your input") + #f #f)) ((only) (datetime date: (date year: (rule-from rule) month: 1 day: 1))) @@ -403,4 +411,12 @@ expries rules aren't yet implemented.") type)] (warning (_ "%z not yet implemented")) fmt-string] - [else (error (_ "Invalid format char"))]))) + [else (scm-error 'misc-error "zone-format" + ;; first slot is the errornous character, + ;; second is the whole string, third is the index + ;; of the faulty character. + (_ "Invalid format char ~s in ~s at position ~a") + (list (string-index fmt-string (1+ idx)) + fmt-string + (1+ idx)) + #f)]))) |