Fix date parsing
This commit is contained in:
		| @ -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) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user