@@ -12,13 +12,34 @@ table! {
1212 }
1313}
1414
15+ #[ cfg( feature = "postgres" ) ]
16+ table ! {
17+ has_timestamptzs {
18+ id -> Integer ,
19+ created_at -> Timestamptz ,
20+ updated_at -> Timestamptz ,
21+ }
22+ }
23+
1524table ! {
1625 has_time {
1726 id -> Integer ,
1827 time -> Time ,
1928 }
2029}
2130
31+ #[ cfg( feature = "postgres" ) ]
32+ table ! {
33+ nullable_date_and_time {
34+ id -> Integer ,
35+ timestamp -> Nullable <Timestamp >,
36+ timestamptz -> Nullable <Timestamptz >,
37+ time -> Nullable <Time >,
38+ date -> Nullable <Date >,
39+ }
40+ }
41+
42+ #[ cfg( not( feature = "postgres" ) ) ]
2243table ! {
2344 nullable_date_and_time {
2445 id -> Integer ,
@@ -226,6 +247,30 @@ fn adding_interval_to_timestamp() {
226247 assert_eq ! ( expected_data, actual_data) ;
227248}
228249
250+ #[ test]
251+ #[ cfg( feature = "postgres" ) ]
252+ fn adding_interval_to_timestamptz ( ) {
253+ use self :: has_timestamptzs:: dsl:: * ;
254+ use diesel:: dsl:: sql;
255+
256+ let connection = connection ( ) ;
257+ setup_test_table ( & connection) ;
258+ connection
259+ . execute (
260+ "INSERT INTO has_timestamptzs (created_at, updated_at) VALUES
261+ ('2015-11-15 06:07:41+0100', '2015-11-15 20:07:41+0100')" ,
262+ )
263+ . unwrap ( ) ;
264+
265+ let expected_data = select ( sql :: < sql_types:: Timestamptz > (
266+ "'2015-11-16 06:07:41+0100'::timestamptz" ,
267+ ) ) . get_result :: < PgTimestamp > ( & connection) ;
268+ let actual_data = has_timestamptzs
269+ . select ( created_at + 1 . day ( ) )
270+ . first :: < PgTimestamp > ( & connection) ;
271+ assert_eq ! ( expected_data, actual_data) ;
272+ }
273+
229274#[ test]
230275#[ cfg( feature = "postgres" ) ]
231276fn adding_interval_to_nullable_things ( ) {
@@ -236,8 +281,8 @@ fn adding_interval_to_nullable_things() {
236281 setup_test_table ( & connection) ;
237282 connection
238283 . execute (
239- "INSERT INTO nullable_date_and_time (timestamp, date, time) VALUES
240- ('2017-08-20 18:13:37', '2017-08-20', '18:13:37')" ,
284+ "INSERT INTO nullable_date_and_time (timestamp, timestamptz, date, time) VALUES
285+ ('2017-08-20 18:13:37', '2017-08-20 18:13:37+0100', '2017-08-20 ', '18:13:37')" ,
241286 )
242287 . unwrap ( ) ;
243288
@@ -249,6 +294,14 @@ fn adding_interval_to_nullable_things() {
249294 . first :: < Option < PgTimestamp > > ( & connection) ;
250295 assert_eq ! ( expected_data, actual_data) ;
251296
297+ let expected_data = select ( sql :: < Nullable < sql_types:: Timestamptz > > (
298+ "'2017-08-21 18:13:37+0100'::timestamptz" ,
299+ ) ) . get_result :: < Option < PgTimestamp > > ( & connection) ;
300+ let actual_data = nullable_date_and_time
301+ . select ( timestamptz + 1 . day ( ) )
302+ . first :: < Option < PgTimestamp > > ( & connection) ;
303+ assert_eq ! ( expected_data, actual_data) ;
304+
252305 let expected_data = select ( sql :: < Nullable < sql_types:: Timestamp > > (
253306 "'2017-08-21'::timestamp" ,
254307 ) ) . get_result :: < Option < PgTimestamp > > ( & connection) ;
@@ -281,6 +334,19 @@ fn setup_test_table(conn: &TestConnection) {
281334 ) . execute ( conn)
282335 . unwrap ( ) ;
283336
337+ #[ cfg( feature = "postgres" ) ]
338+ create_table (
339+ "has_timestamptzs" ,
340+ (
341+ integer ( "id" ) . primary_key ( ) . auto_increment ( ) ,
342+ timestamptz ( "created_at" ) . not_null ( ) ,
343+ timestamptz ( "updated_at" )
344+ . not_null ( )
345+ . default ( "CURRENT_TIMESTAMP" ) ,
346+ ) ,
347+ ) . execute ( conn)
348+ . unwrap ( ) ;
349+
284350 create_table (
285351 "has_time" ,
286352 (
@@ -295,6 +361,8 @@ fn setup_test_table(conn: &TestConnection) {
295361 (
296362 integer ( "id" ) . primary_key ( ) . auto_increment ( ) ,
297363 timestamp ( "timestamp" ) ,
364+ #[ cfg ( feature = "postgres" ) ]
365+ timestamptz ( "timestamptz" ) ,
298366 time ( "time" ) ,
299367 date ( "date" ) ,
300368 ) ,
0 commit comments