File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,15 @@ describe('Shell BSON', function () {
381381 }
382382 expect . fail ( 'expected error' ) ;
383383 } ) ;
384+ it ( 'passes through non-string args to `new Date()`' , function ( ) {
385+ expect ( shellBson . ISODate ( ) ) . to . be . an . instanceOf ( Date ) ;
386+ expect ( shellBson . ISODate ( 0 ) . getTime ( ) ) . to . equal ( 0 ) ;
387+ expect ( shellBson . ISODate ( null ) . getTime ( ) ) . to . equal ( 0 ) ;
388+ expect ( shellBson . ISODate ( 1234 ) . getTime ( ) ) . to . equal ( 1234 ) ;
389+ expect ( shellBson . ISODate ( shellBson . ISODate ( 1234 ) ) . getTime ( ) ) . to . equal (
390+ 1234
391+ ) ;
392+ } ) ;
384393 } ) ;
385394 describe ( 'BinData' , function ( ) {
386395 it ( 'expects strings as base 64' , function ( ) {
Original file line number Diff line number Diff line change @@ -261,8 +261,11 @@ export default function constructShellBson(
261261 } ,
262262 { prototype : bson . Long . prototype }
263263 ) ,
264- ISODate : function ISODate ( input ?: string ) : Date {
265- if ( ! input ) input = new Date ( ) . toISOString ( ) ;
264+ ISODate : function ISODate (
265+ input ?: string | number | Date | undefined
266+ ) : Date {
267+ if ( input === undefined ) return new Date ( ) ;
268+ if ( typeof input !== 'string' ) return new Date ( input ) ;
266269 const isoDateRegex =
267270 / ^ (?< Y > \d { 4 } ) - ? (?< M > \d { 2 } ) - ? (?< D > \d { 2 } ) ( [ T ] (?< h > \d { 2 } ) ( : ? (?< m > \d { 2 } ) ( : ? ( (?< s > \d { 2 } ) ( \. (?< ms > \d + ) ) ? ) ) ? ) ? (?< tz > Z | ( [ + - ] ) ( \d { 2 } ) : ? ( \d { 2 } ) ? ) ? ) ? $ / ;
268271 const match = isoDateRegex . exec ( input ) ;
You can’t perform that action at this time.
0 commit comments