Fix date-with-no-separator transform.

The expected string length was hard-coded, which is not a good idea given
the support for custom date formats.
This commit is contained in:
Dimitri Fontaine 2018-03-07 23:07:00 +01:00
parent 42c9ccfbb3
commit 3112adea6f

View File

@ -102,21 +102,23 @@
"Apply this function when input date in like '20041002152952'" "Apply this function when input date in like '20041002152952'"
;; only process non-zero dates ;; only process non-zero dates
(declare (type (or null string) date-string)) (declare (type (or null string) date-string))
(cond ((null date-string) nil) (let ((str-length (length date-string))
((string= date-string "") nil) (expected-length (reduce #'max (mapcar #'third format))))
((not (= 14 (length date-string))) nil) (cond ((null date-string) nil)
(t ((string= date-string "") nil)
(destructuring-bind (&key year month day hour minute seconds ((not (= expected-length str-length)) nil)
&allow-other-keys) (t
(loop (destructuring-bind (&key year month day hour minute seconds
for (name start end) in format &allow-other-keys)
append (list name (subseq date-string start end))) (loop
(if (or (string= year "0000") for (name start end) in format
(string= month "00") append (list name (subseq date-string start end)))
(string= day "00")) (if (or (string= year "0000")
nil (string= month "00")
(format nil "~a-~a-~a ~a:~a:~a" (string= day "00"))
year month day hour minute seconds)))))) nil
(format nil "~a-~a-~a ~a:~a:~a"
year month day hour minute seconds)))))))
(defun time-with-no-separator (defun time-with-no-separator
(time-string (time-string