* 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
#:gregorian-to-mjd
#:mjd-to-gregorian
#:iso-timestring
#:gregorian-to-mjd
#:mjd-to-gregorian
#:iso-timestring
+ #:time-to-utc
+ #:time-to-localtime
))
(:documentation "This is the INTERNAL SQL-Interface package of CLSQL."))
))
(:documentation "This is the INTERNAL SQL-Interface package of CLSQL."))
(setf (time-is-utc? newt) T)
newt)))
(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))
(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))
(deftest :time/iso-parse/8
(let* ((time1 (parse-timestring "2010-01-23T14:56:32-05:30")))
(decode-time time1))
(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.
(deftest :time/print-parse/1
;;make sure when we print and parse we get the same time.