Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joeframbach opened this issue Aug 25, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@joeframbach
Copy link

joeframbach commented Aug 25, 2023

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.

@joeframbach joeframbach added the bug Something isn't working label Aug 25, 2023
joeframbach added a commit to joeframbach/happy-dom that referenced this issue Aug 25, 2023
@capricorn86
Copy link
Owner

It should be possible to set timezone for the entire NodeJS process by just adding the environment variable TZ=utc.

Example 1:

     {
           "scripts": {
                 "test": "TZ=utc jest"
            }
     }

Example 2:

process.env.TZ = 'Europe/Amsterdam' 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants