Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Summary
# Change

{FIXME}
## Issues

- #{FIXME}

# Details
## Summary

{FIXME}

# Changes in action
## Changes in action

{FIXME}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ $> npm run testem:ci
### Kyle Simpsons

See his [What the... JavaScript?](https://www.youtube.com/watch?v=2pL28CcEijU) lecture, from [forwardJS.com](http://forwardjs.com/)

## References

- [`new Date("wtf")`](https://jsdate.wtf/)
- [*"I hate JavaScript"*, Theo - t3.gg](https://www.youtube.com/watch?v=7bvBVBy_CrM)
131 changes: 131 additions & 0 deletions __tests__/Date/wtf.unit.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// SRC: https://jsdate.wtf/
describe('Date', () => {
let oDate, dateString, dateValue, milliseconds

// 1 of 28
describe('new Date("0")', () => {
beforeEach(() => {
oDate = new Date('0')
dateString = oDate.toISOString()
})

it('does NOT equal "1970-01-01T00:00:00.000Z"', () => {
expect(dateString).not.toEqual('1970-01-01T00:00:00.000Z')
})

// 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!', () => {
expect(dateString).not.toEqual('2000-01-01T00:00:00.000Z') // According to https://jsdate.wtf
expect(dateString).toEqual('2000-01-01T06:00:00.000Z')
})
})

// 2 of 28
describe('new Date(0)', () => {
beforeEach(() => {
oDate = new Date(0)
dateString = oDate.toISOString()
})

it('does NOT equal "2000-01-01T00:00:00.000Z"', () => {
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', () => {
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')

expect(firstDate === secondDate).not.toBe(false)
expect(firstDate === secondDate).toBe(true)
})
})

// 4 of 28
describe('new Date("not a date")', () => {
beforeEach(() => {
oDate = new Date('not a date')
dateValue = oDate.valueOf()
})

it('is NOT null', () => {
expect(oDate).not.toBe(null)
})

it('is NOT undefined', () => {
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)
expect(dateValue).toBeNaN()
})

// 5 of 28
describe('.getTime()', () => {
beforeEach(() => {
milliseconds = oDate.getTime()
})

it('is NOT null', () => {
expect(milliseconds).not.toBe(null)
})

it('is NOT 0', () => {
expect(milliseconds).not.toBe(0)
})

// 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)
expect(milliseconds).toBeNaN()
})
})

// 6 of 28
describe('.toISOString()', () => {
// toISOString() throws a RangeError on Invalid Date objects.
it('throws an error', () => {
expect(() => oDate.toISOString()).toThrow()
})
})

// 7 of 28
describe('.toTimeString()', () => {
beforeEach(() => {
dateString = oDate.toTimeString()
})

it('does NOT equal ""', () => {
expect(dateString).not.toEqual('')
})

it('is NOT null', () => {
expect(dateString).not.toBe(null)
})

// toTimeString() returns the string "Invalid Date" for invalid dates. 🫠
it('equals "Invalid Date"', () => {
expect(dateString).toEqual('Invalid Date')
})
})
})
})