Skip to content

Conversation

@kettanaito
Copy link
Member

@kettanaito kettanaito merged commit 4851315 into main Oct 21, 2024
4 checks passed
@kettanaito kettanaito deleted the fix/use-explicit-timezone branch October 21, 2024 14:22

<CodeFile file="greet.test.ts" range="3-9" highlight="3,6-8" />

<callout-warning>I recommend providing an entire UTC date, including an explicit timezone, as the value of the mocked date to have a resilient test setup: `new OriginalDate('2024-01-01 00:00:00.000Z')`</callout-warning>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great addition for folks in other timezones @kettanaito!

One interesting thing although, I tested it here setting to new OriginalDate('2024-01-01 00:00:00.000Z') and it didn't work (Still getting Sunday), but when using new OriginalDate('2024-01-01 00:00:00.000') (without the Z) it worked.

I guess it's because it sets a UTC timezone, but the greet function still displays time in the Local Timezone, which means that it converts the timezone from UTC to local.

console.log(new Date('2024-01-01 00:00:00.000Z'))
// Sun Dec 31 2023 16:00:00 GMT-0800 (Pacific Standard Time)

console.log(new Date('2024-01-01 00:00:00.000'))
// Mon Jan 01 2024 00:00:00 GMT-0800 (Pacific Standard Time)
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to best deal with timezone issues with the Date method?

3 participants