From e958aa99bf0ca21dd4341e99467fae9a8b24e0d2 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 25 Oct 2025 20:44:40 -0700 Subject: [PATCH] Fix date parsing --- clash/parse-date.lisp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/clash/parse-date.lisp b/clash/parse-date.lisp index 483d5f6..bb76372 100644 --- a/clash/parse-date.lisp +++ b/clash/parse-date.lisp @@ -132,10 +132,6 @@ least one range given will match (that is, the union of all given dates).~%")) :multi-line-mode t) func) out))) - (def-no-time "^$" - (lambda (source registers) - (declare (ignore source registers)) - (local-time:now))) (def-no-time "[0-9]+" (lambda (source registers) (declare (ignore registers)) @@ -209,28 +205,34 @@ least one range given will match (that is, the union of all given dates).~%")) (defun parse-date-range (string) "Parse a date range from STRING." (let ((sep (search ".." string))) - (when (not sep) - (error 'date-parse-error - :source string - :message "expected \"..\" to separate start and end date")) - (let ((second-sep (search ".." string :start2 (1+ sep)))) - (when second-sep - (error 'date-parse-error :source string - :position second-sep - :message "multiple \"..\" found"))) - (macrolet ((trim (str) - `(string-trim '(#\Tab #\Space #\Newline) ,str))) - (cons (parse-date-time (trim (subseq string 0 sep))) - (parse-date-time (trim (subseq string (+ sep 2)))))))) + (if (not sep) + (parse-date-time string) + (progn + (let ((second-sep (search ".." string :start2 (1+ sep)))) + (when second-sep + (error 'date-parse-error :source string + :position second-sep + :message "multiple \"..\" found"))) + (let* ((start (string-trim '(#\Tab #\Space #\Newline) + (subseq string 0 sep))) + (end (string-trim '(#\Tab #\Space #\Newline) + (subseq string (+ sep 2))))) + (when (and (zerop (length start)) + (zerop (length end))) + (error "Invalid date range: ~S" string)) + (cons (when (plusp (length start)) + (parse-date-time start)) + (when (plusp (length end)) + (parse-date-time end)))))))) (defun timestamp-in-ranges (stamp ranges) "Return non-nil if STAMP is in one of RANGES." (some (lambda (range) (destructuring-bind (start . end) range - (when (local-time:timestamp> start end) + (when (and start end (local-time:timestamp> start end)) (rotatef start end)) - (and (local-time:timestamp>= stamp start) - (local-time:timestamp<= stamp end)))) + (and (or (not start) (local-time:timestamp>= stamp start)) + (or (not end) (local-time:timestamp<= stamp end))))) ranges)) (defclass option-multi-parsed (clingon:option)