From 80fa35fdf35c3ecd5cb98a1dfb553314597a2f62 Mon Sep 17 00:00:00 2001 From: JCGuerrero Date: Mon, 29 Sep 2025 18:11:31 -0500 Subject: [PATCH 1/4] f --- __tests__/Date/wtf.unit.spec.js | 179 +++++++++++++++++++++++++++++--- 1 file changed, 167 insertions(+), 12 deletions(-) diff --git a/__tests__/Date/wtf.unit.spec.js b/__tests__/Date/wtf.unit.spec.js index 7905166..e77e823 100644 --- a/__tests__/Date/wtf.unit.spec.js +++ b/__tests__/Date/wtf.unit.spec.js @@ -15,8 +15,8 @@ describe('Date', () => { // FIXME? it matches in CI, but not in my local. // Is it because I am on GMT-6? - // The string "0" is interpreted as the year 2000, not as a timestamp! xit('interprets "0" as the year 2000, not as a timestamp!', () => { + // The string "0" is interpreted as the year 2000, not as a timestamp! expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z') // According to https://jsdate.wtf expect(dateString).toEqual('2000-01-01T06:00:00.000Z') }) @@ -33,22 +33,22 @@ describe('Date', () => { expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z') }) - // The number 0, as opposed to the string "0", - // is interpreted as milliseconds since the Unix epoch (Jan 1, 1970). - it('interprets 0 as a timestamp', () => { + it('is interpreted as 0 milliseconds since the Unix epoch (Jan 1, 1970).', () => { + // The number 0, as opposed to the string "0", + // is interpreted as milliseconds since the Unix epoch (Jan 1, 1970). expect(dateString).toEqual('1970-01-01T00:00:00.000Z') }) }) // 3 of 28 describe('Date.parse(0) === Date.parse("0")', () => { - // Both parse to 946684800000 milliseconds! - // Date.parse only operates on strings, - // so 0 is coerced to the string "0". it('is true', () => { const firstDate = Date.parse(0) const secondDate = Date.parse('0') + // Both parse to 946684800000 milliseconds! + // Date.parse only operates on strings, + // so 0 is coerced to the string "0". expect(firstDate === secondDate).not.toBe(false) expect(firstDate === secondDate).toBe(true) }) @@ -57,6 +57,8 @@ describe('Date', () => { // 4 of 28 describe('new Date("not a date")', () => { beforeEach(() => { + // Invalid Date is still a Date object! + // It's not null or an error. oDate = new Date('not a date') dateValue = oDate.valueOf() }) @@ -69,8 +71,6 @@ describe('Date', () => { expect(oDate).not.toBe(undefined) }) - // Invalid Date is still a Date object! - // It's not null or an error. it('is Invalid Date', () => { expect(Number.isNaN(dateValue)).not.toBe(false) expect(Number.isNaN(dateValue)).toBe(true) @@ -80,6 +80,7 @@ describe('Date', () => { // 5 of 28 describe('.getTime()', () => { beforeEach(() => { + // This function returns the number of milliseconds since the Unix epoch for valid dates. milliseconds = oDate.getTime() }) @@ -92,7 +93,6 @@ describe('Date', () => { }) // Invalid Date objects return NaN for getTime(). - // This function returns the number of milliseconds since the Unix epoch for valid dates. it('is NaN', () => { expect(Number.isNaN(milliseconds)).not.toBe(false) expect(Number.isNaN(milliseconds)).toBe(true) @@ -103,7 +103,7 @@ describe('Date', () => { // 6 of 28 describe('.toISOString()', () => { // toISOString() throws a RangeError on Invalid Date objects. - it('throws an error', () => { + it('throws a RangeError on Invalid Date objects.', () => { expect(() => oDate.toISOString()).toThrow() }) }) @@ -122,10 +122,165 @@ describe('Date', () => { expect(dateString).not.toBe(null) }) - // toTimeString() returns the string "Invalid Date" for invalid dates. 🫠 + it('returns the string "Invalid Date" for invalid dates. 🫠', () => { + // toTimeString() returns the string "Invalid Date" for invalid dates. 🫠 + expect(dateString).toEqual('Invalid Date') + }) + }) + }) + + // 8 of 28 + describe('new Date("1")', () => { + beforeEach(() => { + oDate = new Date('1') + dateString = oDate.toISOString() + }) + + it('does NOT equal "1970-01-01T00:00:00.001Z"', () => { + expect(dateString).not.toEqual('1970-01-01T00:00:00.001Z') + }) + + it('does NOT equal "0001-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('0001-01-01T00:00:00.000Z') + }) + + // FIXME? it matches in CI, but not in my local. + // Is it because I am on GMT-6? + xit('equals to "2001-01-01T00:00:00.000Z"', () => { + // Unlike "0", "1" is interpreted as a month, + // and the year defaults to 2001 for some reason. + expect(dateString).toEqual('2001-01-01T00:00:00.000Z') + }) + }) + + // 9 of 28 + describe('new Date("2")', () => { + beforeEach(() => { + oDate = new Date('2') + dateString = oDate.toISOString() + }) + + it('does NOT equal "2002-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2002-01-01T00:00:00.000Z') + }) + + it('does NOT equal "2001-01-02T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-01-02T00:00:00.000Z') + }) + + xit('equals "2001-02-01T00:00:00.000Z"', () => { + expect(dateString).toEqual('2001-02-01T00:00:00.000Z') + }) + }) + + // 10 of 28 + describe('new Date("12")', () => { + beforeEach(() => { + oDate = new Date('12') + dateString = oDate.toISOString() + }) + + it('does NOT equal "2012-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2012-01-01T00:00:00.000Z') + }) + + it('does NOT equal "2001-01-12T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-01-12T00:00:00.000Z') + }) + + xit('equals "2001-12-01T00:00:00.000Z"', () => { + // Also works for December. + expect(dateString).toEqual('2001-12-01T00:00:00.000Z') + }) + }) + + // 11 of 28 + describe('new Date("13")', () => { + beforeEach(() => { + oDate = new Date('13') + dateString = oDate.toTimeString() + }) + + describe('.toISOString()', () => { + it('throws', () => { + expect(() => oDate.toISOString()).toThrow() + }) + }) + + describe('.toTimeString()', () => { + it('equals "Invalid Date"', () => { + // "13" would be month 13, which doesn't exist, so it's Invalid Date. + expect(dateString).toEqual('Invalid Date') + }) + }) + }) + + // 12 of 28 + describe('new Date("99") > new Date("100")', () => { + it('is true', () => { + const firstDate = new Date('99') // 1999 + const secondDate = new Date('100') // year 0100 + + // "99" is year 1999, + // while "100" is year 0100. + // 1999 > 0100! Date starts interpreting numbers as years starting at "32". + expect(firstDate > secondDate).not.toBe(false) + expect(firstDate > secondDate).toBe(true) + }) + }) + + // 13 of 28 + describe('new Date("49") > new Date("50")', () => { + it('is true', () => { + const firstDate = new Date('49') // 2049 + const secondDate = new Date('50') // 1950 + + // And for some reason "32" to "49" is 2032-2049, + // while "50" onwards is 1950+. So 2049 > 1950! + expect(firstDate > secondDate).not.toBe(false) + expect(firstDate > secondDate).toBe(true) + }) + }) + + // 14 of 28 + describe('new Date("12.1")', () => { + beforeEach(() => { + oDate = new Date('12.1') + dateString = oDate.toISOString() + }) + + it('does NOT equal "2001-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-01-01T00:00:00.000Z') + }) + + it('does NOT equal "2012-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2012-01-01T00:00:00.000Z') + }) + + xit('equals "2001-12-01T00:00:00.000Z"', () => { + // "12.1" is interpreted as the date December 1st, + // and as before for dates with no year the default is 2001 because of course. + expect(dateString).toEqual('2001-12-01T00:00:00.000Z') + }) + }) + + // 15 of 28 + describe('new Date("12.0")', () => { + beforeEach(() => { + oDate = new Date('12.0') + dateString = oDate.toTimeString() + }) + + describe('.toTimeString()', () => { it('equals "Invalid Date"', () => { expect(dateString).toEqual('Invalid Date') }) }) + + describe('.toISOString()', () => { + it('throws', () => { + expect(() => oDate.toISOString()).toThrow() + }) + }) }) }) From 4359162ee44ca57fff33406684e41882ee1d406c Mon Sep 17 00:00:00 2001 From: JCGuerrero Date: Mon, 29 Sep 2025 18:24:50 -0500 Subject: [PATCH 2/4] ff --- __tests__/Date/wtf.unit.spec.js | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/__tests__/Date/wtf.unit.spec.js b/__tests__/Date/wtf.unit.spec.js index e77e823..9a0f5da 100644 --- a/__tests__/Date/wtf.unit.spec.js +++ b/__tests__/Date/wtf.unit.spec.js @@ -283,4 +283,89 @@ describe('Date', () => { }) }) }) + + // 16 of 28 + describe('new Date("12.-1")', () => { + beforeEach(() => { + oDate = new Date('12.-1') + dateString = oDate.toISOString() + }) + + it('does NOT equal "2012-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2012-01-01T00:00:00.000Z') + }) + + it('does NOT equal "2001-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-01-01T00:00:00.000Z') + }) + + xit('ignores the "-", interpreting it like "12.1", resulting in "2001-12-01T00:00:00.000Z"', () => { + // The dash here is ignored, so this is interpreted the same as "12.1". + expect(dateString).toEqual('2001-12-01T00:00:00.000Z') + }) + }) + + // 17 of 28 + describe('new Date("perhaps 1")', () => { + beforeEach(() => { + oDate = new Date('perhaps 1') + dateString = oDate.toISOString() + }) + + it('does NOT equal "1970-01-01T00:00:01.000Z"', () => { + expect(dateString).not.toEqual('1970-01-01T00:00:01.000Z') + }) + + xit('ignores leading text. Finding "1" and parsing it as January. Resulting in "2001-01-01T00:00:00.000Z"', () => { + // Leading text is always ignored! + // It finds the "1" and parses it as the month January. + expect(dateString).toEqual('2001-01-01T00:00:00.000Z') + }) + }) + + // 18 of 28 + describe('new Date("perhaps")', () => { + beforeEach(() => { + // But you can't just have text! + // It needs a number to parse, so this is Invalid Date. + // It's equivalent to new Date(""). + oDate = new Date('perhaps') + dateString = oDate.toTimeString() + }) + + describe('.toTimeString()', () => { + it('equals "Invalid Date"', () => { + expect(dateString).toEqual('Invalid Date') + }) + }) + + describe('.toISOString()', () => { + it('throws', () => { + expect(() => oDate.toISOString()).toThrow() + }) + }) + }) + + // 19 of 28 + describe('new Date("maybe 1")', () => { + beforeEach(() => { + oDate = new Date('maybe 1') + dateString = oDate.toISOString() + }) + + it('does NOT equal "2001-05-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-05-01T00:00:00.000Z') + }) + + it('does NOT equal "2001-01-01T00:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-01-01T00:00:00.000Z') + }) + + xit('parses "maybe" as "may"! resulting in "2001-05-01T00:00:00.000Z"', () => { + // "may" in "maybe" is parsed as the month May! + // And for some reason this expression cares about your local timezone, + // which happens to be BST for me right now. + expect(dateString).toEqual('2001-05-01T00:00:00.000Z') + }) + }) }) From 246617096bfb4adfc30b89e6e83132752a601687 Mon Sep 17 00:00:00 2001 From: JCGuerrero Date: Mon, 29 Sep 2025 18:29:21 -0500 Subject: [PATCH 3/4] fff --- __tests__/Date/wtf.unit.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/Date/wtf.unit.spec.js b/__tests__/Date/wtf.unit.spec.js index 9a0f5da..ea3663f 100644 --- a/__tests__/Date/wtf.unit.spec.js +++ b/__tests__/Date/wtf.unit.spec.js @@ -353,8 +353,8 @@ describe('Date', () => { dateString = oDate.toISOString() }) - it('does NOT equal "2001-05-01T00:00:00.000Z"', () => { - expect(dateString).not.toEqual('2001-05-01T00:00:00.000Z') + it('does NOT equal "2001-04-30T23:00:00.000Z"', () => { + expect(dateString).not.toEqual('2001-04-30T23:00:00.000Z') }) it('does NOT equal "2001-01-01T00:00:00.000Z"', () => { From 8951cca2c38a65009d684aec654c61b77ceaf160 Mon Sep 17 00:00:00 2001 From: JCGuerrero Date: Mon, 29 Sep 2025 18:30:04 -0500 Subject: [PATCH 4/4] d --- __tests__/Date/wtf.unit.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/__tests__/Date/wtf.unit.spec.js b/__tests__/Date/wtf.unit.spec.js index ea3663f..b6850d8 100644 --- a/__tests__/Date/wtf.unit.spec.js +++ b/__tests__/Date/wtf.unit.spec.js @@ -353,6 +353,7 @@ describe('Date', () => { dateString = oDate.toISOString() }) + // WARNING: The quiz says this is the correct answer! it('does NOT equal "2001-04-30T23:00:00.000Z"', () => { expect(dateString).not.toEqual('2001-04-30T23:00:00.000Z') })