-
-
Notifications
You must be signed in to change notification settings - Fork 864
Fix dates being initialized with client timezone when using timestamps #288
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
Conversation
Honestly, I'm not sure if there are hidden implications of adding this. Could you add an integration test for this behavior? |
I'm not very familiar with unit testing, but I think I got it working correctly. |
test.serial('timestamp timezone', async (t) => { | ||
const { db } = t.context; | ||
|
||
await db.insert(usersTable).values({ name: 'John' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test inserting a Date with a non-default timezone specified? I'm curious if it'll change the date string format returned from the driver on selection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I added the test as you specified for both mysql and postgres timestamps. Upon running the tests I found out that timestamps are by default inserted respecting the client's timezone as well, instead of in UTC format. I pushed a fix for this behavior, which passed all the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you have a code formatter (Prettier, probably) enabled on save, which changed the formatting quite a bit. We use Dprint for this repo, so please re-format the files with it (it might not rollback some formatting you already did, so you'll have to change it back manually).
@AppelBoomHD please resolve the merge conflicts |
a3e11c8
to
7293f88
Compare
Timestamps in mysql and postgressql are by default save as UTC timestamps.
Javascripts Date initializer assumes that dates are written in the client's timezone, when no explicit timezone is given in the initializer. This PR manually adds the UTC timezone to the initializer string.
Another way to this is (https://stackoverflow.com/a/3075893/13799537):
In TypeScript this gives a couple type-errors, which is why I chose the more simple one-liner solution.