From 0e172b4b2d6dc5a6dd016c0803a2a98955ffe8f3 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Thu, 10 Nov 2016 19:13:53 -0800
Subject: [PATCH] Fix #36: encode-universal-time errors on valid time

Allow 1899 as a year, but also add a check that the resulting time is
a non-negative integer.

Add a test for this too in issues.lisp.
---
 src/code/time.lisp | 7 +++++--
 tests/issues.lisp  | 5 +++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/code/time.lisp b/src/code/time.lisp
index 51457f517..bf853a2b6 100644
--- a/src/code/time.lisp
+++ b/src/code/time.lisp
@@ -223,8 +223,11 @@
 	   (type (mod 24) hour)
 	   (type (integer 1 31) date)
 	   (type (integer 1 12) month)
-	   (type (or (integer 0 99) (integer 1900)) year)
-	   (type (or null rational) time-zone))
+	   ;; 1899 to account for time zones that are equivalent to 1900.
+	   (type (or (integer 0 99) (integer 1899)) year)
+	   (type (or null rational) time-zone)
+	   ;; Result must be non-negative integer!
+	   (values (integer 0)))
   (let* ((year (if (< year 100)
 		   (pick-obvious-year year)
 		   year))
diff --git a/tests/issues.lisp b/tests/issues.lisp
index 6bd341344..4e5640c22 100644
--- a/tests/issues.lisp
+++ b/tests/issues.lisp
@@ -347,3 +347,8 @@
     (assert (null (set-difference directories
                                   '(".dir" "dir")
                                   :test #'string-equal)))))
+
+(define-test issue.36
+    (:tag :issues)
+  (loop for k from 1 to 24 do
+    (assert-equal 0 (encode-universal-time 0 0 (- 24 k) 31 12 1899 k))))
-- 
GitLab