File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -97,9 +97,8 @@ function dateToString(date) {
9797 // Invalid dates can occur from new Date(undefined), new Date(NaN), etc.
9898 // See https://github.com/brianc/node-postgres/issues/3318
9999 if ( ! date || ! ( date instanceof Date ) || isNaN ( date . getTime ( ) ) ) {
100- throw new TypeError ( 'Cannot serialize invalid date' ) ;
100+ throw new TypeError ( 'Cannot serialize invalid date' )
101101 }
102-
103102 let offset = - date . getTimezoneOffset ( )
104103 let year = date . getFullYear ( )
105104 const isBCYear = year < 1
@@ -137,7 +136,7 @@ function dateToStringUTC(date) {
137136 // Invalid dates can occur from new Date(undefined), new Date(NaN), etc.
138137 // See https://github.com/brianc/node-postgres/issues/3318
139138 if ( ! date || ! ( date instanceof Date ) || isNaN ( date . getTime ( ) ) ) {
140- throw new TypeError ( 'Cannot serialize invalid date' ) ;
139+ throw new TypeError ( 'Cannot serialize invalid date' )
141140 }
142141
143142 let year = date . getUTCFullYear ( )
Original file line number Diff line number Diff line change @@ -314,3 +314,28 @@ testEscapeIdentifier(
314314 'hello \\ \' " world' ,
315315 '"hello \\ \' "" world"'
316316)
317+
318+ test ( 'prepareValue: invalid date from undefined throws error' , function ( ) {
319+ assert . throws ( ( ) => {
320+ utils . prepareValue ( new Date ( undefined ) )
321+ } , / C a n n o t s e r i a l i z e i n v a l i d d a t e / )
322+ } )
323+
324+ test ( 'prepareValue: invalid date from NaN throws error' , function ( ) {
325+ assert . throws ( ( ) => {
326+ utils . prepareValue ( new Date ( NaN ) )
327+ } , / C a n n o t s e r i a l i z e i n v a l i d d a t e / )
328+ } )
329+
330+ test ( 'prepareValue: invalid date from invalid string throws error' , function ( ) {
331+ assert . throws ( ( ) => {
332+ utils . prepareValue ( new Date ( 'invalid' ) )
333+ } , / C a n n o t s e r i a l i z e i n v a l i d d a t e / )
334+ } )
335+
336+ test ( 'prepareValue: valid date still works correctly' , function ( ) {
337+ const date = new Date ( '2024-01-01T12:00:00Z' )
338+ const result = utils . prepareValue ( date )
339+ assert ( typeof result === 'string' )
340+ assert ( result . includes ( '2024' ) )
341+ } )
You can’t perform that action at this time.
0 commit comments