From b4b36caa84292f176dd377ac91e0cdb7b3856f23 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 26 Jul 2015 14:41:44 +0200 Subject: [PATCH] Fix parsing dates with less-than 4 digits, fix #266. The previous coding decided to add 2000 to the year as an integer if it was below 2000, which parses 1999 as 3999. Oops. Trigger the correction only when the date is given on 2 digits only, parsing 04 as 2004. Dates given on 3 digits are kept as-is. Playing with the *century* special parameter allows to cancel this behavior, that maybe should be made entirely optional. It's just too common to find current years on 2 digits only, sadly. --- src/parsers/date-format.lisp | 3 ++- src/sources/common/project-fields.lisp | 1 - test/csv-parse-date.load | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/parsers/date-format.lisp b/src/parsers/date-format.lisp index 3fc2fdf..8a31a68 100644 --- a/src/parsers/date-format.lisp +++ b/src/parsers/date-format.lisp @@ -44,7 +44,8 @@ (with-output-to-string (s) (format s "~a-~a-~a ~a:~a:~a" (let ((yint (parse-integer year))) - (if (< yint *century*) (+ *century* yint) yint)) + ;; process 2-digits year formats specially + (if (<= (length year) 2) (+ *century* yint) yint)) month day (let ((hint (parse-integer hour))) diff --git a/src/sources/common/project-fields.lisp b/src/sources/common/project-fields.lisp index 1e7fa57..7069c11 100644 --- a/src/sources/common/project-fields.lisp +++ b/src/sources/common/project-fields.lisp @@ -41,7 +41,6 @@ (list (cdr field-name-or-list)) (t (cdr (assoc field-name-or-list fields :test #'string-equal)))) - (declare (ignore date-format)) ; TODO ;; now prepare a function of a column (lambda (col) (let ((value-or-null diff --git a/test/csv-parse-date.load b/test/csv-parse-date.load index fee2d28..72184e5 100644 --- a/test/csv-parse-date.load +++ b/test/csv-parse-date.load @@ -19,6 +19,6 @@ LOAD CSV ); $$; -1,2014-10-02 00-33-12.123456 +1,1999-10-02 00-33-12.123456 2,2014-10-02 00-33-13.123456 3,2014-10-02 00-33-14.123456