Skip to content

dateIsoWeek depends on the timezone of the machine running the tests #1026

@joeframbach

Description

@joeframbach

Describe the bug
At https://github.com/capricorn86/happy-dom/blob/master/packages/happy-dom/src/nodes/html-input-element/HTMLInputElementDateUtility.ts#L17-L19, date.getDay() is dependent on the timezone of the machine. The results are inconsistent.

To Reproduce
Steps to reproduce the behavior:

$ TZ="UTC" npm run test -- --no-cache --force
happy-dom:test:  Test Files  89 passed (89)
happy-dom:test:       Tests  2344 passed (2344)

$ TZ="US/Pacific" npm run test -- --no-cache --force

happy-dom:test:  FAIL  test/nodes/html-input-element/HTMLInputDateUtility.test.ts > HTMLInputElementDateUtility > dateToIsoWeek() > Returns the ISO week number
happy-dom:test: AssertionError: expected '2021-W02' to be '2021-W01' // Object.is equality

happy-dom:test:  FAIL  test/nodes/html-input-element/HTMLInputDateUtility.test.ts > HTMLInputElementDateUtility > IsoWeekToDate() > Returns the ISO week number
happy-dom:test: AssertionError: expected 2020-12-29T00:00:00.000Z to deeply equal 2020-12-28T00:00:00.000Z

happy-dom:test:  FAIL  test/nodes/html-input-element/HTMLInputElement.test.ts > HTMLInputElement > get valueAsDate() > Should return valid date for type 'week' with valid value
happy-dom:test: AssertionError: expected 2023-05-30T00:00:00.000Z to deeply equal 2023-05-29T00:00:00.000Z

To reproduce the root cause:

$ TZ="US/Pacific" node -e "console.log(new Date('2021-01-03').getDay())"
6

$ TZ="UTC" node -e "console.log(new Date('2021-01-03').getDay())"
0

Expected behavior
Tests should pass anywhere in the world.

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Latest version

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions