+(defun previous-datetime-year (year)
+ "Inverse of NEXT-DATETIME-YEAR, using character arithmetic and no year zero."
+ (labels ((negate (text)
+ (if (char= #\- (char text 0)) (subseq text 1)
+ (concatenate 'string "-" text))))
+ (negate (next-datetime-year (negate year)))))
+
+(defun previous-datetime-date (date)
+ "Previous day under the existing Date validator's calendar contract."
+ (let* ((dash (position #\- date :start (if (char= #\- (char date 0)) 1 0)))
+ (year (subseq date 0 dash))
+ (month (parse-integer date :start (1+ dash) :end (+ dash 3)))
+ (day (parse-integer date :start (+ dash 4) :end (+ dash 6))))
+ (cond ((> day 1) (format nil "~A-~2,'0D-~2,'0D" year month (1- day)))
+ ((= month 1) (concatenate 'string (previous-datetime-year year) "-12-31"))
+ (t (loop for last-day downfrom 31 to 28
+ for candidate = (format nil "~A-~2,'0D-~2,'0D" year (1- month) last-day)
+ when (date-lexical-p candidate) return candidate)))))
+
+(defun datetime-offset-minutes (zone)
+ "Signed whole minutes of an already validated XSD timezone; NIL if absent."
+ (cond ((zerop (length zone)) nil)
+ ((string= zone "Z") 0)
+ (t (* (if (char= #\- (char zone 0)) -1 1)
+ (+ (* 60 (parse-integer zone :start 1 :end 3))
+ (parse-integer zone :start 4 :end 6))))))
+