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

Incorrect offset with datetimeoffset type in SQL Server #1205

Open
penttin5 opened this issue Nov 1, 2024 · 1 comment
Open

Incorrect offset with datetimeoffset type in SQL Server #1205

penttin5 opened this issue Nov 1, 2024 · 1 comment
Labels
built-in dialect Related to a built-in dialect mssql Related to MS SQL Server (MSSQL) question Further information is requested

Comments

@penttin5
Copy link

penttin5 commented Nov 1, 2024

When inserting/updating a Javascript Date value to a column of type datetimeoffset in SQL Server, the offset is always +00:00, which leads to wrong result if useUTC=false and process.env.TZ !== 'UTC'.

input useUTC app's TZ expected actual correct?
new Date('2024-01-01T06:00:00Z') true 'Z' 2024-01-01 06:00:00 +00:00 2024-01-01 06:00:00 +00:00 Y
new Date('2024-01-01T06:00:00Z') true 'Europe/Helsinki' 2024-01-01 06:00:00 +00:00 2024-01-01 06:00:00 +00:00 Y
new Date('2024-01-01T06:00:00Z') false 'Z' 2024-01-01 06:00:00 +00:00 2024-01-01 06:00:00 +00:00 Y
new Date('2024-01-01T06:00:00Z') false 'Europe/Helsinki' 2024-01-01 08:00:00 +02:00 2024-01-01 08:00:00 +00:00 N

Changing the TediousDataType for Date values from #tedious.TYPES.DateTime to #tedious.TYPES.DateTimeOffset in MssqlDriver.#getTediousDataType seems to fix this:

  #getTediousDataType(value: unknown): any {
    ...
    if (isDate(value)) {
-      return this.#tedious.TYPES.DateTime
+      return this.#tedious.TYPES.DateTimeOffset
    }

I don't know enough about Tedious to know what the correct way to fix this is. My guess is that the correct TediousType should be read from the database metadata.

@igalklebanov
Copy link
Member

igalklebanov commented Nov 1, 2024

Hey 👋

Related to #1164. Thanks for raising this!

Check this possible workaround @ #1161 (comment).

@igalklebanov igalklebanov added mssql Related to MS SQL Server (MSSQL) built-in dialect Related to a built-in dialect question Further information is requested labels Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
built-in dialect Related to a built-in dialect mssql Related to MS SQL Server (MSSQL) question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants