Skip to content

fix: datetime max millisecond issue - #762

Merged
arthurschreiber merged 1 commit into
tediousjs:masterfrom
Hadis-Fard:datetimeMaxMS
Oct 28, 2019
Merged

arthurschreiber merged 1 commit into
tediousjs:masterfrom
Hadis-Fard:datetimeMaxMS

Conversation

@Hadis-Fard

Copy link
Copy Markdown

Datetime round millisecond in nearest .xx3, .xx7, .xx0, when the ms is rounded to 000 in case of 23:59:59:999, day should be incremented. the issue manifest itself in useUTC true or false

Fixes: #755

@Suraiya-Hameed

Copy link
Copy Markdown
Member

Looks good. Can you add a test too? Under \test\integration\datatypes-in-resultset, maybe?

threeHundredthsOfSecond = milliseconds / (3 + (1 / 3));
threeHundredthsOfSecond = Math.round(threeHundredthsOfSecond);
// 25920000 equals one day
if (threeHundredthsOfSecond === 25920000) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this the maximum value threeHundredthsOfSecond can have?

@Hadis-Fard Hadis-Fard Jul 31, 2018 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

according to TDS

One 4-byte signed integer that represents the number of days since January 1, 1900. Negative numbers are allowed to represent dates since January 1, 1753.
One 4-byte unsigned integer that represents the number of one three-hundredths of a second (300 counts per second) elapsed since 12 AM that day

the buffer consists of days/threehundredth of a second, 25920000 equals to a full day and if we hit it, we should increment the day

@arthurschreiber

Copy link
Copy Markdown
Collaborator

Is this fix "correct"? According to #524, this failure might be due to a bug in SQL Server itself?

@Hadis-Fard

Copy link
Copy Markdown
Author

@arthurschreiber it makes sense since the number of days and time are sent separately, so if the time is full 24 hrs then it should change the day. this fixed the two tests mentioned in #524

@MichaelSun90

Copy link
Copy Markdown
Contributor

Hi @arthurschreiber, I have looked into this issue and I think this is a valid and important fix. However, I think we can still add some extra comments to make it more clear.

As the comment on line 40, we could add some extra explanation to clear things up:
// Since we are rounding milliseconds to 300ths of a second (the precision of a DateTime), if we happen
// to round up to a full day's worth of 300ths of a second (25920000 ), we need to carry that over to the // day part

In addition, I think we can add some comments above line 38 to just explain the expression: milliseconds / (3 + (1 / 3)). I just want to confirm with you first that I understand this correctly. Is this expression equivalent to "milliseconds /1000 * 300"? I understand this as convert millisecond number back to seconds by divided it by 1000 and count the "one three-hundredths of a second" by dividing it with 300. If this is correct, is it better for us to add some comment here to explain this?

Is it possible for you to help add the comments to this PR, or I can create a new PR and you can close this one?

@daviduzumeri

daviduzumeri commented Oct 7, 2019 •

Copy link
Copy Markdown

Any movement on this? This just bit my ass passing in an end-of-day value. Basically any time you try to do an outer limit of 23:59:59.999 in a where clause it'll explode on you. Came here to submit the issue and it looks like this is the exact same one.

@codecov

codecov Bot commented Oct 27, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #762 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #762      +/-   ##
==========================================
+ Coverage   77.61%   77.62%   +0.01%     
==========================================
  Files          86       86              
  Lines        4230     4233       +3     
  Branches      779      780       +1     
==========================================
+ Hits         3283     3286       +3     
  Misses        675      675              
  Partials      272      272
Impacted Files Coverage Δ
src/data-types/datetime.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55154fc...b246b56. Read the comment docs.

@arthurschreiber
arthurschreiber merged commit fc7cd33 into tediousjs:master Oct 28, 2019
@arthurschreiber

Copy link
Copy Markdown
Collaborator

Thank you very much for preparing this @Hadis-Fard, sorry this has taken so long to get merged! 🙇

@arthurschreiber

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 6.6.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DateTime precision error.

5 participants