-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Fix report days calculation to account for DST #33036
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
|
📊 Test reports for this pull request have been published and are accessible through the following links:
Latest commit referenced in the reports: Visit the WooCommerce Test Reports homepage to view all published reports. See the FAQs page if you're having problems accessing them. |
louwie17
left a comment
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.
This tested well, and thanks for fixing this 🥇
I did leave a couple questions, as I was slightly confused by some of the logic in there. I trust your changes, but want to make sure.
| 'quarter' => 1, | ||
| 'year' => 1, | ||
| ), | ||
| ), |
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.
Should we be explicitly setting the timezone to a DST adhering timezone for this test? Given it might not be using that as the timezone?
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 idea. Updated to set a specific timezone in 15decc9.
| $start_hour_min_sec = (int) $start_datetime->format( 'H' ) * HOUR_IN_SECONDS + (int) $start_datetime->format( 'i' ) * MINUTE_IN_SECONDS + (int) $start_datetime->format( 's' ); | ||
| if ( $end_hour_min_sec < $start_hour_min_sec ) { | ||
| $addendum = 1; | ||
| $days++; |
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.
I don't quite understand this condition, at-least it was never hit when running the monthly reports.
Is this only relevant when looking at specific times of day? (which I don't think we can do, or at-least not in revenue).
If this logic is specifically for DST, should we add a comment describing it?
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.
This is pre-existing logic and unrelated to the DST logic. I updated where the variable gets added to make it more clear, but logic here remains the same.
You can see similar logic in other time units, but I believe how this works is counting partial days. For example, the diff of days between 10-01-2022 12:00:00 and 10-02-2022 11:00:00 would be 0 since no full days exist. Adding the check for end time allows us to count those partial days.
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.
Thanks for the extra explanation, that clarifies that.
| $end_timestamp = (int) $end_datetime->format( 'U' ); | ||
| $start_timestamp = (int) $start_datetime->format( 'U' ); | ||
| $addendum = 0; | ||
| $days = $start_datetime->diff( $end_datetime )->format( '%r%a' ); |
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.
Nice use of diff instead 💯
louwie17
left a comment
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.
LGTM 🚀 thanks for the update in the tests and giving some extra clarification on the logic. ![]()
|
Hi @joshuatf, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
All Submissions:
Changes proposed in this Pull Request:
Updates the calculation for days between two dates to fix issues where DST based timezones would miscalculate days and cause reports to not be exported properly.
Closes #32220 .
How to test the changes in this Pull Request:
Other information:
pnpm nx changelog <project>?FOR PR REVIEWER ONLY: