From 3112adea6fc4b74ededc58391700fd7c46b0ee1e Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Wed, 7 Mar 2018 23:07:00 +0100 Subject: [PATCH] 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. --- src/utils/transforms.lisp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index 7dfa473..5a14334 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -102,21 +102,23 @@ "Apply this function when input date in like '20041002152952'" ;; only process non-zero dates (declare (type (or null string) date-string)) - (cond ((null date-string) nil) - ((string= date-string "") nil) - ((not (= 14 (length date-string))) nil) - (t - (destructuring-bind (&key year month day hour minute seconds - &allow-other-keys) - (loop - for (name start end) in format - append (list name (subseq date-string start end))) - (if (or (string= year "0000") - (string= month "00") - (string= day "00")) - nil - (format nil "~a-~a-~a ~a:~a:~a" - year month day hour minute seconds)))))) + (let ((str-length (length date-string)) + (expected-length (reduce #'max (mapcar #'third format)))) + (cond ((null date-string) nil) + ((string= date-string "") nil) + ((not (= expected-length str-length)) nil) + (t + (destructuring-bind (&key year month day hour minute seconds + &allow-other-keys) + (loop + for (name start end) in format + append (list name (subseq date-string start end))) + (if (or (string= year "0000") + (string= month "00") + (string= day "00")) + nil + (format nil "~a-~a-~a ~a:~a:~a" + year month day hour minute seconds))))))) (defun time-with-no-separator (time-string