-
-
Notifications
You must be signed in to change notification settings - Fork 269
Surgical port of core logic improvements: Date, DSQL, and Sort #8978
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
Open
laBobberto
wants to merge
4
commits into
FirebirdSQL:master
Choose a base branch
from
laBobberto:fix_logic_surgical
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−124
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8cea0c0
Port logic improvements: date calculation, DSQL validation, and sort …
laBobberto 89048d6
refactor`sort.cpp`:
laBobberto ea74d68
Replacing bitwise operations in `int NoThrowTimeStamp::convertGregori…
laBobberto f8402ca
Merge branch 'master' into fix_logic_surgical
laBobberto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ const ISC_TIME NoThrowTimeStamp::POW_10_TABLE[] = | |
| NoThrowTimeStamp NoThrowTimeStamp::getCurrentTimeStamp(const char** error) noexcept | ||
| { | ||
| if (error) | ||
| *error = NULL; | ||
| *error = nullptr; | ||
| NoThrowTimeStamp result; | ||
|
|
||
| // NS: We round generated timestamps to whole millisecond. | ||
|
|
@@ -341,51 +341,36 @@ int NoThrowTimeStamp::convertGregorianDateToWeekDate(const struct tm& times) noe | |
| { | ||
| // Algorithm for Converting Gregorian Dates to ISO 8601 Week Date by Rick McCarty, 1999 | ||
| // http://personal.ecu.edu/mccartyr/ISOwdALG.txt | ||
|
|
||
| const int y = times.tm_year + 1900; | ||
| const int dayOfYearNumber = times.tm_yday + 1; | ||
| const int dayOfYear = times.tm_yday + 1; | ||
|
|
||
| // Find the jan1Weekday for y (Monday=1, Sunday=7) | ||
| const int yy = (y - 1) % 100; | ||
| const int c = (y - 1) - yy; | ||
| const int g = yy + yy / 4; | ||
| const int y_1 = y - 1; | ||
| const int yy = y_1 % 100; | ||
| const int c = y_1 - yy; | ||
| const int g = yy + (yy / 4); | ||
| const int jan1Weekday = 1 + (((((c / 100) % 4) * 5) + g) % 7); | ||
|
|
||
| // Find the weekday for y m d | ||
| const int h = dayOfYearNumber + (jan1Weekday - 1); | ||
| const int weekday = 1 + ((h - 1) % 7); | ||
| const int weekday = 1 + ((dayOfYear + jan1Weekday - 2) % 7); | ||
|
|
||
| // Find if y m d falls in yearNumber y-1, weekNumber 52 or 53 | ||
| int yearNumber, weekNumber; | ||
|
|
||
| if ((dayOfYearNumber <= (8 - jan1Weekday)) && (jan1Weekday > 4)) | ||
| if ((dayOfYear <= (8 - jan1Weekday)) & (jan1Weekday > 4)) | ||
| { | ||
| yearNumber = y - 1; | ||
| weekNumber = ((jan1Weekday == 5) || ((jan1Weekday == 6) && | ||
| isLeapYear(yearNumber))) ? 53 : 52; | ||
| const int prevYearLeap = (!(y_1 % 4) && ((y_1 % 100) || !(y_1 % 400))); | ||
| const int is53 = (jan1Weekday == 5) | ((jan1Weekday == 6) & prevYearLeap); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that operator | always returns 1 (assigned to int is53), not for example -1? |
||
| return 52 + is53; | ||
| } | ||
| else | ||
| { | ||
| yearNumber = y; | ||
|
|
||
| // Find if y m d falls in yearNumber y+1, weekNumber 1 | ||
| const int i = isLeapYear(y) ? 366 : 365; | ||
|
|
||
| if ((i - dayOfYearNumber) < (4 - weekday)) | ||
| { | ||
| yearNumber = y + 1; | ||
| weekNumber = 1; | ||
| } | ||
| // Find if y m d falls in yearNumber y+1, weekNumber 1 | ||
| const int daysInYear = 365 + (!(y % 4) && ((y % 100) || !(y % 400))); | ||
| if ((daysInYear - dayOfYear) < (4 - weekday)) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| // Find if y m d falls in yearNumber y, weekNumber 1 through 53 | ||
| if (yearNumber == y) | ||
| { | ||
| const int j = dayOfYearNumber + (7 - weekday) + (jan1Weekday - 1); | ||
| weekNumber = j / 7; | ||
| if (jan1Weekday > 4) | ||
| weekNumber--; | ||
| } | ||
| const int j = dayOfYear + (7 - weekday) + (jan1Weekday - 1); | ||
| const int weekNumber = (j / 7) - (jan1Weekday > 4); // Subtract 1 if jan1Weekday > 4 | ||
|
|
||
| return weekNumber; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changing logical && to bitwise & here is plain bug.
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.
You're right, Alex. It was a mistake. Thanks for noticing, I've corrected it and your comment below.