Repository navigation
Fix date calculations for date, datetime, datetime2 and datetimeoffset - #1023
Conversation
This fixes the value calculations for `date`, `datetime`, `datetime2` and `datetimeoffset` to be independent of offset changes that could cause unexpected values to be written to the database. BREAKING CHANGE: This should cause the values to be written to the database to be more in line of what is expected, but can be different for some edge cases.
|
@mrliuc can you check this out? I believe it should fix the weird issues you've been running into around |
Codecov Report
@@ Coverage Diff @@
## master #1023 +/- ##
==========================================
+ Coverage 79.15% 79.31% +0.16%
==========================================
Files 86 86
Lines 4221 4221
Branches 779 780 +1
==========================================
+ Hits 3341 3348 +7
+ Misses 606 601 -5
+ Partials 274 272 -2
Continue to review full report at Codecov.
|
|
For some more background information here - I believe the way we calculated the number of days between the epoch dates for See the following example based on the This behavior only changed semi-recently, with Node 10. Earlier versions had different behaviour, as can be seen here when running the same commands as before on Node.js 8: This update in Node 10 was based on a change in V8 to better reflect timezone handling and be more compliant with the EcmaScript standard, but it caused the days calculation as implemented in This PR switches all these day calculations over to be based on This also removes the special code that was added in |
|
@arthurschreiber I did some test, when I insert into DB and Millisecond>997, The time part is wrong ,It's hard to describe, Here's the test code and results, when you see it,you will konw code: results: |
|
@mrliuc This is expected behaviour in SQL Server - the This behaviour is documented here: https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-ver15#rounding-of-datetime-fractional-second-precision As mentioned at the top of the linked page, you should probably move to |
|
@dhensby Can you run this against the |
|
@arthurschreiber datetime2 & datetimeoffset has a different but similar issue , I inserted into DB '2019-12-19 23:59:59:998',the data in DB was '2019-12-19 23:59:59.9980000',when I selected,I got '2019-12-19 23:59:59:997' I saw the test suite in node-mssql and I think it's not comprehensive enough, the test suite just select the variable like this: It's not enough,you must insert into the really db like this: Then this line of code will get the result unequal PS:the test code about datetime2,datetimeoffset |
|
It seems like :
I would rather use the datetime,unless you're going to be compatible with this issue. |
|
@mrliuc If you need millisecond accuracy, then You can try the following to see this is an issue on SQL Server that can't be fixed in SELECT CONVERT(varchar, CAST('2019-11-19 23:59:59:998' as datetime), 127);
-- 2019-11-19T23:59:59.997
SELECT CONVERT(varchar, CAST('2019-11-19 23:59:59:998' as datetime2), 127);
-- 2019-11-19T23:59:59.9980000I also added additional test cases in 37c63ed that should show that we're handling Did you update the |
|
@arthurschreiber You are right,I find a bug in my test case , It's all pass now.Thank you very much |
37c63ed to
d64b506
Compare
I have tested it locally and the previously failing test is now passing 🎉 |
|
🎉 This PR is included in version 8.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This changes the date calculations to not be based on Unix Epoch milliseconds, but on actual days between the data types base time and the given value.
This should fix all weirdness around DST changes and other timezone related shenanigans.
Fixes: #1018
References: #883, #755