+
+
+;;; The cross platform dataset uses the 'timestamp' column type which is
+;;; in sql-92, for all that means.
+
+(deftest :time/cross-platform/no-usec/no-tz
+ (with-dataset *cross-platform-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29")))
+ (clsql-sys:insert-records :into [datetest]
+ :attributes '([testtime])
+ :values (list time))
+ (let ((testtime
+ (first (clsql:select [testtime]
+ :from [datetest] :flatp t
+ :where [= [testtime] time] ))))
+ (format-time nil (parse-timestring testtime) :format :iso)
+ )))
+ #.(format-time nil (parse-timestring "2008-09-09T14:37:29") :format :iso))
+
+(deftest :time/cross-platform/no-usec/tz
+ (with-dataset *cross-platform-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29-04:00")))
+ (clsql-sys:insert-records :into [datetest]
+ :attributes '([testtime])
+ :values (list time))
+ (let ((testtime
+ (first (clsql:select [testtime]
+ :from [datetest] :flatp t
+ :where [= [testtime] time] ))))
+ (format-time nil (parse-timestring testtime) :format :iso)
+ )))
+ #.(format-time nil (parse-timestring "2008-09-09T14:37:29-04:00") :format :iso))
+
+;;;This test gets at the databases that only support miliseconds,
+;;; not microseconds.
+(deftest :time/cross-platform/msec
+ (with-dataset *cross-platform-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29.423")))
+ (clsql-sys:insert-records :into [datetest]
+ :attributes '([testtime])
+ :values (list time))
+ (let ((testtime
+ (first (clsql:select [testtime]
+ :from [datetest] :flatp t
+ :where [= [testtime] time] ))))
+ (format-time nil (parse-timestring testtime) :format :iso)
+ )))
+ #.(format-time nil (parse-timestring "2008-09-09T14:37:29.423") :format :iso))
+
+(deftest :time/cross-platform/usec/no-tz
+ (with-dataset *cross-platform-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29.000213")))
+ (clsql-sys:insert-records :into [datetest]
+ :attributes '([testtime])
+ :values (list time))
+ (let ((testtime
+ (first (clsql:select [testtime]
+ :from [datetest] :flatp t
+ :where [= [testtime] time] ))))
+ (format-time nil (parse-timestring testtime) :format :iso)
+ )))
+ #.(format-time nil (parse-timestring "2008-09-09T14:37:29.000213") :format :iso))
+
+(deftest :time/cross-platform/usec/tz
+ (with-dataset *cross-platform-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29.000213-04:00")))
+ (clsql-sys:insert-records :into [datetest]
+ :attributes '([testtime])
+ :values (list time))
+ (let ((testtime
+ (first (clsql:select [testtime]
+ :from [datetest]
+ :limit 1 :flatp t
+ :where [= [testtime] time] ))))
+ (format-time nil (parse-timestring testtime) :format :iso)
+ )))
+ #.(format-time nil (parse-timestring "2008-09-09T14:37:29.000213-04:00") :format :iso))
+
+
+
+
+;;; All odbc databases use local times exclusively (they do not send timezone info)
+;;; Postgresql can use timezones, except when being used over odbc. This test when
+;;; run through both postgres socket and postgres odbc should test a fairly
+;;; broad swath of available problem space
+;;;
+;;; Things the following tests try to prove correct
+;;; * Reading and writing usec and usec-less times
+;;; * reading and writing timezones (Z=utc) when appropriate (eg: postgresql-socket)
+;;; * reading and writing localtimes when appropriate (eg: ODBC)
+;;; * reading and writing through both the oodml and fdml layers
+
+
+
+(deftest :time/pg/fdml/usec
+ (with-dataset *ds-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29.000213-04:00")))
+ (clsql-sys:insert-records :into [datetest]
+ :attributes '([testtimetz] [testtime])
+ :values (list time time))
+ (destructuring-bind (testtimetz testtime)
+ (first (clsql:select [testtimetz] [testtime]
+ :from [datetest]
+ :limit 1 :flatp t
+ :where [= [testtime] time] ))
+ (values (iso-timestring (parse-timestring testtime))
+ (iso-timestring (parse-timestring testtimetz))))))
+ #.(iso-timestring (parse-timestring "2008-09-09T14:37:29.000213-04:00"))
+ #.(iso-timestring (parse-timestring "2008-09-09T14:37:29.000213-04:00")))
+
+(deftest :time/pg/oodml/no-usec
+ (with-dataset *ds-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29-04:00")))
+ (clsql-sys:update-records-from-instance
+ (make-instance 'datetest :testtimetz time :testtime time))
+ (let ((o (first (clsql:select
+ 'datetest
+ :limit 1 :flatp t
+ :where [= [testtime] time] ))))
+ (assert o (o) "o shouldnt be null here (we should have just inserted)")
+ (update-records-from-instance o)
+ (update-instance-from-records o)
+ (values (iso-timestring (testtime o))
+ (iso-timestring (testtimetz o))))))
+ #.(iso-timestring (parse-timestring "2008-09-09T14:37:29-04:00"))
+ #.(iso-timestring (parse-timestring "2008-09-09T14:37:29-04:00")))
+
+(deftest :time/pg/oodml/usec
+ (with-dataset *ds-datetest*
+ (let ((time (parse-timestring "2008-09-09T14:37:29.000278-04:00")))
+ (clsql-sys:update-records-from-instance
+ (make-instance 'datetest :testtimetz time :testtime time))
+ (let ((o (first (clsql:select
+ 'datetest
+ :limit 1 :flatp t
+ :where [= [testtime] time] ))))
+ (assert o (o) "o shouldnt be null here (we should have just inserted)")
+ (update-records-from-instance o)
+ (update-instance-from-records o)
+ (values (iso-timestring (testtime o))
+ (iso-timestring (testtimetz o)))
+ )))
+ #.(iso-timestring (parse-timestring "2008-09-09T14:37:29.000278-04:00"))
+ #.(iso-timestring (parse-timestring "2008-09-09T14:37:29.000278-04:00")))
+