From 0994944677f02e7f9842f4d041d34876bbef2d51 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 9 Apr 2021 10:57:37 +0200 Subject: [PATCH] fix(shell-api): remove custom Date constructor MONGOSH-597 --- packages/cli-repl/test/e2e.spec.ts | 1 - packages/shell-api/src/shell-bson.spec.ts | 16 ---------------- packages/shell-api/src/shell-bson.ts | 19 ------------------- 3 files changed, 36 deletions(-) diff --git a/packages/cli-repl/test/e2e.spec.ts b/packages/cli-repl/test/e2e.spec.ts index c754eca2fb..ce394e737b 100644 --- a/packages/cli-repl/test/e2e.spec.ts +++ b/packages/cli-repl/test/e2e.spec.ts @@ -376,7 +376,6 @@ describe('e2e', function() { await shell.waitForPrompt(); shell.assertNoErrors(); - await shell.executeLine('Date.now = () => new Date().getTime()'); // MONGOSH-597 hack await shell.executeLine(`use ${dbName}`); await shell.executeLine('db.test.insertOne({ d: new Date("2021-04-07T11:24:54+02:00") })'); shell.writeInputLine(`load(${JSON.stringify(require.resolve('lodash'))})`); diff --git a/packages/shell-api/src/shell-bson.spec.ts b/packages/shell-api/src/shell-bson.spec.ts index 055fb275ef..a52ec5584d 100644 --- a/packages/shell-api/src/shell-bson.spec.ts +++ b/packages/shell-api/src/shell-bson.spec.ts @@ -222,22 +222,6 @@ describe('Shell BSON', () => { expect(s.code).to.equal(''); }); }); - describe('Date', () => { - it('returns string without new', () => { - expect(shellBson.Date()).to.be.a('string'); - }); - it('accepts ISO args', () => { - expect((new (shellBson.Date as any)(1) as Date).getTime()).to.equal(1); - expect((new (shellBson.Date as any)(1, 2) as Date).getTime()).to.equal(-2172355200000); - expect((new (shellBson.Date as any)(1, 2, 3, 4, 5) as Date).getTime()).to.equal(-2172167700000); - }); - it('returns now object with new', () => { - const date = new (shellBson.Date as any)(); - const cDate = new Date(); - expect(typeof date).to.equal('object'); - expect(date.getFullYear()).to.equal(cDate.getFullYear()); - }); - }); describe('ISODate', () => { it('ISODate is always object', () => { const date = new (shellBson.ISODate as any)(); diff --git a/packages/shell-api/src/shell-bson.ts b/packages/shell-api/src/shell-bson.ts index e0dc83a0cf..e3ee2a7dac 100644 --- a/packages/shell-api/src/shell-bson.ts +++ b/packages/shell-api/src/shell-bson.ts @@ -16,18 +16,6 @@ function constructHelp(className: string): Help { return new Help(classHelp); } -type DateConstructorArguments = [ any?, any?, ...any[] ]; - -function dateHelper(...args: DateConstructorArguments): Date { - if (args.length === 0) { - return new Date(); - } - if (args.length === 1) { - return new Date(args[0]); - } - return new Date(Date.UTC(...args)); -} - /** * This method modifies the BSON class passed in as argument. This is required so that * we can have help, serverVersions, and other metadata on the bson classes constructed by the user. @@ -112,13 +100,6 @@ export default function constructShellBson(bson: typeof BSON, printWarning: (msg printWarning('NumberLong: specifying a number as argument is deprecated and may lead to loss of precision'); return bson.Long.fromInt(s); }, - Date: function(...args: DateConstructorArguments): Date | string { - const date = dateHelper(...args); - if (new.target) { - return date; - } - return date.toString(); - }, ISODate: function(input?: string): Date { if (!input) input = new Date().toISOString(); const isoDateRegex =