Skip to content

Conversation

@joshuatf
Copy link
Contributor

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:

  1. Select a timezone (US, London, etc) that utilizes DST in your site's General settings
  2. Install an email logging plugin
  3. Go to the Revenue report
  4. Select October 1 - October 31 as a custom date
  5. Click "Download" to export the report
  6. Check your email logs to make sure the report is sent and can be downloaded
  7. Check that the number of "days" is correct in the summary numbers at the bottom of the Revenue report
  8. Smoketest other areas of the app to make sure no regressions have occurred

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm nx changelog <project>?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@joshuatf joshuatf self-assigned this May 13, 2022
@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. labels May 13, 2022
@joshuatf joshuatf requested a review from a team May 16, 2022 17:10
@botwoo
Copy link
Collaborator

botwoo commented May 16, 2022

📊 Test reports for this pull request have been published and are accessible through the following links:

Latest commit referenced in the reports: Update tests to use EST timezone 15decc9
This comment will automatically be updated with the latest referenced commit when you push new changes to this pull request.


Visit the WooCommerce Test Reports homepage to view all published reports. See the FAQs page if you're having problems accessing them.

@louwie17 louwie17 self-requested a review May 20, 2022 14:28
Copy link
Contributor

@louwie17 louwie17 left a 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,
),
),
Copy link
Contributor

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?

Copy link
Contributor Author

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++;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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' );
Copy link
Contributor

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 louwie17 added the needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. label May 20, 2022
@joshuatf joshuatf removed the needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. label May 23, 2022
Copy link
Contributor

@louwie17 louwie17 left a 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. :shipit:

@joshuatf joshuatf merged commit 2294082 into trunk May 26, 2022
@joshuatf joshuatf deleted the fix/32220 branch May 26, 2022 20:55
@github-actions github-actions bot added this to the 6.7.0 milestone May 26, 2022
@github-actions
Copy link
Contributor

Hi @joshuatf, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

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

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When requesting to download a Revenue Report for the Last Month no report is emailed

4 participants