• Resolved damadmai

    (@damadmai)


    Hi!

    sucuri.php:
    In the function prettify_mail() which is used for sending the notification E-Mail the function current_datetime() calls function datetime() which should return the current time.

    I’m in Timezone Berlin GMT+1. Plus 1 hour Daylight Saving Time.
    In the Audit Logs the correct time is shown but in my Mail I get the time offset added twice!

    If I use the following function instead of current_datetime in function prettify_mail() everithing works fine:

    public static function current_datetime2(){
            $local_time = self::local_time();
    
            $gmt_offset = get_option( 'gmt_offset' );
            if ( is_numeric( $gmt_offset ) ) {
                    $local_time -= ( $gmt_offset * 3600 );
            }
    
            return self::datetime( $local_time );
        }

    I wanted to open an Ticket in Trac but it seems that this isn’t possible?

    Kind Regards

    https://ww.wp.xz.cn/plugins/sucuri-scanner/

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter damadmai

    (@damadmai)

    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

    Thread Starter damadmai

    (@damadmai)

    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

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Notification E-Mail Timezone’ is closed to new replies.