@@ -960,23 +960,28 @@ export class MongoStorageAdapter implements StorageAdapter {
960960 return pipeline ;
961961 }
962962
963- // This function will attempt to convert the provided value to a Date object. Since this is part
964- // of an aggregation pipeline, the value can either be a string or it can be another object with
965- // an operator in it (like $gt, $lt, etc). Because of this I felt it was easier to make this a
966- // recursive method to traverse down to the "leaf node" which is going to be the string.
963+ /**
964+ * Recursively converts values to Date objects. Since the passed object is part of an aggregation
965+ * pipeline and can contain various logic operators (like $gt, $lt, etc), this function will
966+ * traverse the object and convert any strings that can be parsed as dates into Date objects.
967+ * @param {any } value The value to convert.
968+ * @returns {any } The original value if not convertible to Date, or a Date object if it is.
969+ */
967970 _convertToDate ( value : any ) : any {
968971 if ( value instanceof Date ) {
969972 return value ;
970973 }
971974 if ( typeof value === 'string' ) {
972- return new Date ( value ) ;
975+ return isNaN ( Date . parse ( value ) ) ? value : new Date ( value ) ;
973976 }
974-
975- const returnValue = { } ;
976- for ( const field in value ) {
977- returnValue [ field ] = this . _convertToDate ( value [ field ] ) ;
977+ if ( typeof value === 'object' ) {
978+ const returnValue = { } ;
979+ for ( const field in value ) {
980+ returnValue [ field ] = this . _convertToDate ( value [ field ] ) ;
981+ }
982+ return returnValue ;
978983 }
979- return returnValue ;
984+ return value ;
980985 }
981986
982987 _parseReadPreference ( readPreference : ?string ) : ?string {
0 commit comments