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) |                                                   :multi-line-mode t) | ||||||
|                          func) |                          func) | ||||||
|                    out))) |                    out))) | ||||||
|       (def-no-time "^$" |  | ||||||
|           (lambda (source registers) |  | ||||||
|             (declare (ignore source registers)) |  | ||||||
|             (local-time:now))) |  | ||||||
|       (def-no-time "[0-9]+" |       (def-no-time "[0-9]+" | ||||||
|           (lambda (source registers) |           (lambda (source registers) | ||||||
|             (declare (ignore 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) | (defun parse-date-range (string) | ||||||
|   "Parse a date range from STRING." |   "Parse a date range from STRING." | ||||||
|   (let ((sep (search ".." string))) |   (let ((sep (search ".." string))) | ||||||
|     (when (not sep) |     (if (not sep) | ||||||
|       (error 'date-parse-error |         (parse-date-time string) | ||||||
|              :source string |         (progn | ||||||
|              :message "expected \"..\" to separate start and end date")) |  | ||||||
|           (let ((second-sep (search ".." string :start2 (1+ sep)))) |           (let ((second-sep (search ".." string :start2 (1+ sep)))) | ||||||
|             (when second-sep |             (when second-sep | ||||||
|               (error 'date-parse-error :source string |               (error 'date-parse-error :source string | ||||||
|                                        :position second-sep |                                        :position second-sep | ||||||
|                                        :message "multiple \"..\" found"))) |                                        :message "multiple \"..\" found"))) | ||||||
|     (macrolet ((trim (str) |           (let* ((start (string-trim '(#\Tab #\Space #\Newline) | ||||||
|                  `(string-trim '(#\Tab #\Space #\Newline) ,str))) |                                      (subseq string 0 sep))) | ||||||
|       (cons (parse-date-time (trim (subseq string 0 sep))) |                  (end (string-trim '(#\Tab #\Space #\Newline) | ||||||
|             (parse-date-time (trim (subseq string (+ sep 2)))))))) |                                    (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) | (defun timestamp-in-ranges (stamp ranges) | ||||||
|   "Return non-nil if STAMP is in one of RANGES." |   "Return non-nil if STAMP is in one of RANGES." | ||||||
|   (some (lambda (range) |   (some (lambda (range) | ||||||
|           (destructuring-bind (start . end) range |           (destructuring-bind (start . end) range | ||||||
|             (when (local-time:timestamp> start end) |             (when (and start end (local-time:timestamp> start end)) | ||||||
|               (rotatef start end)) |               (rotatef start end)) | ||||||
|             (and (local-time:timestamp>= stamp start) |             (and (or (not start) (local-time:timestamp>= stamp start)) | ||||||
|                  (local-time:timestamp<= stamp end)))) |                  (or (not end) (local-time:timestamp<= stamp end))))) | ||||||
|         ranges)) |         ranges)) | ||||||
|  |  | ||||||
| (defclass option-multi-parsed (clingon:option) | (defclass option-multi-parsed (clingon:option) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user