-
Notifications
You must be signed in to change notification settings - Fork 800
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
CRM: Fix dashboard contact graph #38316
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! |
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, thanks for working on this.
What would be the best way to change the timezone? In my case I created a contact and set the creation date for June 30th UTC+0, evening. Changed my timezone in WordPress to UTC+13 which changed the contact creation date to July 1st. The dashboard graph still shows the contact entry for June, both with and without the PR.
That's a great question. That should've bugged the dashboard's graph. Adjust inside your database |
Yes that's how I adjusted the |
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.
To test this way:
We could use the WP installation timezone configured:
$datetime_month = new DateTime( '@', $v->ts );
$datetime_month->setTimezone( new DateTimeZone('the_UTC_time_zone') );
$the_month = $datetime_month->format( 'M y' );
@cleacos Do you mean the existing code could be replaced by the suggested code there? Not sure I'm following on that, but I tried doing so using the 'Europe/London' DateTimeZone, and encountered an issue because of the '@' - |
👋 Indeed, this is a timezone-related bug! However, this PR wouldn't fix it.
There are a few ways to handle this. My recommendation is to NOT rely on
My preferred solution would be to set the MySQL timezone to If there's not an easy way to adjust the timezone globally, you can try something like this:
However, I'm not sure if
Technically For testing, I'd recommend using a creation date of As an aside, there might be another place that is affected in the same way:
|
Per this comment in documentation, there may be an undocumented |
Tried, didn't work. |
It works! Thanks, @tbradsha! |
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 changes!
I tested again, and this time I got what I believe is the expected result (different to last time), but want to make sure that's expected:
- I set the contact creation date to late in the day UTC+0 Sep 30th. The contact shows in September in the dashboard. I then change the site timezone to UTC+13 - the contact now shows in October in the dashboard.
- Same results following the suggestion here - I changed the creation date to 1st Jan (but 2024, not 2028), 0:00:00 and 1:00:00 UTC. The dashboard continues to show the contact in Jan regardless of timezone change without the PR, and with the PR if the timezone change switches the creation date to the previous month the dashboard now reflects that.
Based on your description, it sounds like it's doing what it should: showing the creation date based on the currently-selected WP timezone. |
@@ -69,17 +69,20 @@ function jetpackcrm_dash_refresh() { | |||
); | |||
} | |||
|
|||
$tz_offset = esc_sql( (string) jpcrm_get_wp_timezone_offset() ); |
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.
Not a blocker, but the cast should be unnecessary, as wp_timezone_string()
should always return a valid string, and everything else uses built-ins.
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'm escaping this because we are not calling wp_timezone_string
directly.
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.
Yep, I was referring to the cast. :^)
$datetime_month = DateTime::createFromFormat( '!m Y', $v->month . ' ' . $v->year ); | ||
$the_month = $datetime_month->format( 'M y' ); |
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 still think the timestamp way is more readable than this way, though that'd require keeping that column in the database.
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.
Seems to work.
Fixes https://github.com/Automattic/zero-bs-crm/issues/3468
Proposed changes:
Other information:
Jetpack product discussion
https://github.com/Automattic/zero-bs-crm/issues/3468
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Alternatively just test the new code and check if the behavior is consistently the same as the previous, and that the new code looks good enough.