Dates and Times have incorrect timezone offsets
under review
Matheus Martins
I have a bug I’d like to report regarding incorrectly formatted dates and times displayed throughout the plugin. The easiest way to demonstrate this is on the Donor Dashboard. On the Dashboard, users are presented with their “Last donated {TIME} ago”. Go ahead add a test donation for that user now and you’ll notice how this time difference is incorrect.
The issue has to do with the fact that all dates stored in the give_donationmeta table are being saved in the site’s timezone, rather than in UTC. (This includes the meta ‘_give_payment_date’, the data in ‘_give_payment_meta’, and ‘_give_completed_date’.) As such, functions like strtotime(), which assume that they’re working with UTC, end up incorrectly formatting the date and adding the local timezone offset.
Technically, the fix for this is pretty easy. The simple way to fix it is to tell functions like strtotime() that the string they’re dealing with is already in the WP Timezone.
So for example, in wp-content/plugins/give/src/DonorDashboards/Profile.php replacing line 83:
'sinceLastDonation' => ! empty( $this->donor->get_last_donation_date() ) ? human_time_diff( strtotime( $this->donor->get_last_donation_date() ) ) : '',
With this:
'sinceLastDonation' => ! empty( $this->donor->get_last_donation_date() ) ? human_time_diff( strtotime( $this->donor->get_last_donation_date() . ' ' . wp_timezone_string() ) ) : '',
The alternate solution is to keep things consistent with how WordPress and MySQL like to store dates (and how they’re already being stored in the give_donors table in ‘date_created’ and ‘verify_throttle’) and store them in the database in UTC. It may be worth the effort as then, should a site admin need to change a site’s timezone, this wouldn’t affect donations as they’d be displayed correctly after the change.
I also noticed that you’re using the date_i18n() which is a bit of a depricated function that oftentimes ends up again formatting the date/times with the wrong offset. To see this in action, let’s temporarily change the give_date_format to include times:
add_filter( 'give_date_format', 'custom_give_date_format' );
function custom_give_date_format( $date_format_contexts ) {
return 'F j, Y g:i a';
}
Now go to the Donors admin page. You’ll notice how all dates are actually being output in UTC rather than with the correct site’s timezone offset.
The fix for this is really easy: replace date_i18n() with the newer wp_date() which will correctly take into account the site’s Timezone and format the dates/times accurately.
rcsupport
the suggested fix seems to work but only for the last donated field
The "Donor for" field still shows the wrong time
I'm not sure if it shows the correct time if you are in a different timezone though to the server/wordpress install
Is there any eta on a fix for this?
Debi Johnson
I have to same issue too. I need our timezone to be able to be changed to reflect our correct timezone so our donations are marked for the correct day.
Ben Meredith
under review
Thanks for this great feedback. I have added this to the board to be looked at.
Issues like this that are not preventing donations or have a simple workaround are generally prioritized at the end of an 8 week development cycle, and then tested and released. That means it can be up to 10 weeks for issues like this to be resolved.
Chris Wakeling
Ben Meredith How about 3 years later and still not resolved? I have noticed that the "Last donated" is an hour out as we are in BST (GMT+1) right now. Check out the screenshots. The donation was made 6 mins ago but yet it is counting down from 60 mins and displays the time as 54 mins ago which is incorrect.