Created time-to-localtime
[clsql.git] / sql / time.lisp
index a7674a89277594218dc6c15b8f02b22701a253ea..39d9e4dc3483a70272ee06d2bdef50185556e2ea 100644 (file)
         (setf (time-is-utc? newt) T)
         newt)))
 
+(defun time-to-localtime (in)
+  "Ensures that if we have a time thats not in UTC, treat it as a localtime,
+   and convert to UTC"
+  (if (not (time-is-utc? in))
+      in
+      (let ((newt
+              (time+ in (make-duration :second (- (%universal-ts-offset in))))))
+        (setf (time-is-utc? newt) nil)
+        newt)))
+
 (defun make-time (&key (year 0) (month 1) (day 1) (hour 0) (minute 0)
                   (second 0) (usec 0) (offset nil))
   (let* ((mjd (gregorian-to-mjd month day year))