@@ -5,17 +5,21 @@ const vm = require('vm')
55const suite = new helper . Suite ( )
66
77suite . testAsync ( 'Handle date objects as Date' , async ( ) => {
8- // Create a valid date timestamp first
8+ // Create a valid timestamp
99 const timestamp = Date . now ( )
10- // Create cross-realm date with the valid timestamp
10+ // Create cross-realm date with valid timestamp and immediately get its value
1111 const crossRealmDate = await vm . runInNewContext ( `new Date(${ timestamp } )` )
1212 assert ( ! ( crossRealmDate instanceof Date ) )
13- // Create local date with same timestamp
13+ // Extract the time value while it's still valid
14+ const crossRealmTime = crossRealmDate . getTime ( )
15+ // Create local dates from the timestamps
1416 const date = new Date ( timestamp )
17+ const crossRealmDateLocal = new Date ( crossRealmTime )
1518 const client = new helper . pg . Client ( )
1619 await client . connect ( )
1720 await client . query ( 'CREATE TEMP TABLE foo(bar timestamptz, bar2 timestamptz)' )
18- await client . query ( 'INSERT INTO foo(bar, bar2) VALUES($1, $2)' , [ date , crossRealmDate ] )
21+ // Use the local date objects, not the cross-realm one
22+ await client . query ( 'INSERT INTO foo(bar, bar2) VALUES($1, $2)' , [ date , crossRealmDateLocal ] )
1923 const results = await client . query ( 'SELECT * FROM foo' )
2024 const row = results . rows [ 0 ]
2125 assert . deepStrictEqual ( row . bar , date )
0 commit comments