Thanks so much, this is very helpful, some people have reported inconsistencies with the timezone before but with your proof of concept I can see where the issue is.
Comparing the current code with your I can see an important difference, my code uses += to reduce the GMT time according to the offset configured by the administrator, but yours uses -=. This make sense because I am located in Colombia with -GMT and you are in Germany with +GMT so the signs must be inverted.
Thanks for your help, I will run some tests and include your patch.
No Problem. I’m wondering why no one else reported that. 🙂
I forgot to mention that the line $local_time -= ( $gmt_offset * 3600 ); subracts the time offset which was added in your function datetime(). I was “too lazy” to reimplement datetime() without your manual gmt_offset ADDition.
So that has nothing to do with my timezone being +1, actually it’s currently +2!
I modified the code following your suggestion with changeset 1210343 [1] I will release this new code in the next version of the plugin (probably next week) after I finish the implementation of other features. You can use the development version [2] for now. Thanks again for your help.
[1] https://plugins.trac.ww.wp.xz.cn/changeset/1210343
[2] https://downloads.wp.xz.cn/plugin/sucuri-scanner.zip
Your old function datetime() was just fine. With this changeset applied the time shown in the audit log (admin.php?page=sucuriscan) gets wrong!
Just changing += to -= has the same effect as your else if !
My suggestion in the beginning was just for the E-Mail generation. (Which gets wrong by -4 now)
I use this code in standard php functions so just modify the code for your class. Gets the correct time and also does the i18n conversion.
$timeNow = time();
$gmt_offset = get_option( 'gmt_offset' ) * 3600;
$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
I removed the GMT addition here [1] and it seemed to work in my tests. regarding the new option that I promised to add, I decided that it was not a good idea after all, people may get more confused with two different options to configure the timezone than by the incorrect times. Lets test this new code and see how it goes.
[1] https://plugins.trac.ww.wp.xz.cn/changeset/1215017