Activities use the wrong time zone

It seems that the plugin isn't using the timezone which is setup in Wordpress. All activities are 2 hours back. Seems like the plugin uses UTC:

UTC time is 2015-08-10 06:29:03 Local time is 2015-08-10 08:29:03

Can you please have a look?

  • Joakim

    Here is the account page with activities. Why shouldn't it be possible to select a city? If you use all the normal PHP and WP functions everything should be fine regarding the date :slight_smile: I changed to UTC+2 but still get the wrong time. Is the date saved human readable and not as timestamp as it should? I tried a few more timezones and none is changing this.

    I've attached a screenshot.

  • Ash

    Hello @Joakim

    Yes, you are right. The time is in UTC format. To resolve this, please use the following code:

    add_filter( 'ms_format_date', 'ms_format_date_cb', 99, 3 );
    function ms_format_date_cb( $result, $date, $format ) {
    	return get_date_time_value( strtotime( $date ), true, true );
    }
    
    function get_date_time_value( $str = false, $date = true, $time = false, $zone = false ){
            $res = '';
            if ( $str == false ) {
                $str = current_time( 'timestamp' );
            }
            if ( $date ) {
                $res .= date_i18n( get_option( 'date_format' ), $str );
            }
            if ( $time ) {
                $res .= ' ' . date_i18n( get_option( 'time_format' ), $str );
            }
            if ( $zone ) {
                $res .= ' UTC ' . ( ( get_option( 'gmt_offset' ) > 0 ) ? '+ ' : '' ) . get_option( 'gmt_offset' );
            }
            return $res;
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.