Created time-to-localtime
authorRuss Tyndall <russ@acceleration.net>
Tue, 6 Feb 2018 17:22:20 +0000 (12:22 -0500)
committerRuss Tyndall <russ@acceleration.net>
Tue, 6 Feb 2018 17:22:20 +0000 (12:22 -0500)
 * allows conversion of utc back to localtime for
   eg: printing
 * exported time-to-utc, time-to-localtime
 * added tests roundtripping times between the two

re ADWolf:#1408

sql/package.lisp
sql/time.lisp
tests/test-time.lisp

index 8915b06781011292d8fdbdbe7ca5f452c96ffb33..9ccb074be44143a4a5e402a065cc12b0b81534b1 100644 (file)
          #:gregorian-to-mjd
          #:mjd-to-gregorian
          #:iso-timestring
+         #:time-to-utc
+         #:time-to-localtime
          ))
     (:documentation "This is the INTERNAL SQL-Interface package of CLSQL."))
 
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))
index d631340a36b15f816c62c547af2931ef52f1637c..b130b99d6c57d72ba538822d5a36879e74fca027 100644 (file)
 (deftest :time/iso-parse/8
     (let* ((time1 (parse-timestring "2010-01-23T14:56:32-05:30")))
       (decode-time time1))
-  0 32 26 20 23 1 2010 6 t)
+ 0 32 26 20 23 1 2010 6 t)
+
+(deftest :time/utc-round-trip/1
+    (let* ((time1 (parse-timestring "2010-01-23T14:56:32")))
+      (decode-time (time-to-localtime (time-to-utc time1))))
+ 0 32 56 14 23 1 2010 6 nil)
+
+(deftest :time/utc-round-trip/2
+    (let* ((time1 (parse-timestring "2010-01-23T14:56:32Z")))
+      (decode-time (time-to-utc (time-to-localtime time1))))
+  0 32 56 14 23 1 2010 6 t)
 
 (deftest :time/print-parse/1
     ;;make sure when we print and parse we get the same time.