@@ -10,7 +10,7 @@ describe("Postgres driver", function() {
1010 describe ( "#valueToProperty" , function ( ) {
1111 var driver = null ;
1212
13- before ( function ( ) {
13+ beforeEach ( function ( ) {
1414 driver = new Driver ( { } , { } , { } ) ;
1515 } ) ;
1616
@@ -72,6 +72,35 @@ describe("Postgres driver", function() {
7272 should . strictEqual ( valueToProperty ( '1.200 ' ) , 1 ) ;
7373 } ) ;
7474 } ) ;
75+
76+ describe ( "dates with non local timezone" , function ( ) {
77+ beforeEach ( function ( ) {
78+ driver = new Driver ( { timezone : 'Z' } , { } , { } ) ;
79+ } ) ;
80+
81+ function valueToProperty ( value ) {
82+ return driver . valueToProperty ( value , { type : 'date' } ) ;
83+ }
84+
85+ it ( "should accept null" , function ( ) {
86+ should . strictEqual ( valueToProperty ( null ) , null ) ;
87+ } ) ;
88+
89+ it ( "should work" , function ( ) {
90+ should . strictEqual ( _ . isDate ( valueToProperty ( new Date ( ) ) ) , true ) ;
91+ } ) ;
92+
93+ describe ( "calculations" , function ( ) {
94+ it ( "should offset time, relative to timezone" , function ( ) {
95+ d = new Date ( ) ;
96+
97+ expected = d . getTime ( ) - d . getTimezoneOffset ( ) * 60000 ;
98+ converted = valueToProperty ( d ) . getTime ( ) ;
99+
100+ should . equal ( converted , expected ) ;
101+ } ) ;
102+ } ) ;
103+ } ) ;
75104 } ) ;
76105 } ) ;
77106
@@ -116,9 +145,24 @@ describe("Postgres driver", function() {
116145 should . equal ( inputStr , out . toString ( ) ) ;
117146 } ) ;
118147
119- it ( "should offset time by specified timezone amount for + timezones" ) ;
148+ it ( "should work with null dates" , function ( ) {
149+ should . strictEqual ( evaluate ( null , { config : { timezone : 'Z' } } ) , null ) ;
150+ } ) ;
151+
152+ it ( "should work with date objects" , function ( ) {
153+ should . strictEqual ( _ . isDate ( evaluate ( new Date ( ) , { config : { timezone : 'Z' } } ) ) , true ) ;
154+ } ) ;
155+
156+ describe ( "calculations" , function ( ) {
157+ it ( "should offset time, relative to timezone" , function ( ) {
158+ d = new Date ( ) ;
159+
160+ expected = d . getTime ( ) + d . getTimezoneOffset ( ) * 60000 ;
161+ converted = evaluate ( d , { config : { timezone : 'Z' } } ) . getTime ( ) ;
120162
121- it ( "should offset time by specified timezone amount for + timezones" ) ;
163+ should . equal ( converted , expected ) ;
164+ } ) ;
165+ } ) ;
122166 } ) ;
123167
124168 describe ( "type point" , function ( ) {
0 commit comments