• The _EVENTDATES _LOCAL{…} placeholder is not retrieving information correctly. While EVENTDATES_LOCAL does so, when used with the custom formatting part {…} it doesn’t retreive the right dates (and times), instead showing 01/01/1970. Picture below illustrates it.

    https://prnt.sc/KYY_68ZCQT1B

Viewing 5 replies - 1 through 5 (of 5 total)
  • I think it’s because of the following error:

    [20-May-2023 20:57:22 UTC] PHP Notice:  Undefined variable: start_time in /home/mafwor5/public_html/staging/wp-content/plugins/events-manager/classes/em-event.php on line 2397
    [20-May-2023 20:57:22 UTC] PHP Notice:  Undefined variable: end_time in /home/mafwor5/public_html/staging/wp-content/plugins/events-manager/classes/em-event.php on line 2397
    

    I think line 2365 of events-manager/classes/em-event.php is incorrect. It should be changed from this:

                            if( empty($time_format) ){

    To this:

                            if( ! empty($time_format) ){

    But this would need more testing to make sure it works correctly.

    Thread Starter fjr9

    (@fjr9)

    Hey @joneiseman, I tried making that chage and the result was that _EVENTDATES _LOCAL{…} now outputs the same as _EVENTDATES _LOCAL (so the right date but without the formatting)

    Thread Starter fjr9

    (@fjr9)

    Update:

    Adding:

    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_date == $this->event_end_date ? $start_time : $this->end()->getTimestamp();

    outside this if statement if( empty($time_format) ){...} fixes the problem. something must be wrong with the original placement of this code.

    • This reply was modified 1 year, 5 months ago by fjr9.
    Thread Starter fjr9

    (@fjr9)

    @joneiseman okay found the final issue and fix.

    This whole section:

    if( $result === '#_EVENTDATES_LOCAL' ){
    $time_format = ( get_option('dbem_date_format') ) ? get_option('dbem_date_format'):get_option('date_format');
    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_date == $this->event_end_date ? $start_time : $this->end()->getTimestamp();
    if( empty($separator) ) $separator = get_option('dbem_dates_separator');
    }else{
    $time_format = ( get_option('dbem_time_format') ) ? get_option('dbem_time_format'):get_option('time_format');
    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_time == $this->event_end_time ? $start_time : $this->end()->getTimestamp();
    if( empty($separator) ) $separator = get_option('dbem_times_separator');
    }

    Should be outside the if( empty($time_format) ){...} function, not inside. This was the error and completely fixes it. Final version, corrected:

    case '#_EVENTTIMES_LOCAL':
    case '#_EVENTDATES_LOCAL':
    if( !defined('EM_JS_MOMENTJS_PH') || EM_JS_MOMENTJS_PH ){
    // check for passed parameters, in which case we skip replacements entirely and use pure moment formats
    $time_format = $separator = null;
    if( !empty($placeholder_atts[1]) ){
    $params = explode(',', $placeholder_atts[1]);
    if( !empty($params[0]) ) $time_format = $params[0];
    if( !empty($params[1]) ) $separator = $params[1];
    }
    if( empty($separator) ) $separator = get_option('dbem_times_separator');
    // if no moment format provided, we convert the one stored for times in php
    if( empty($time_format) ){
    // convert EM format setting to moment formatting, adapted from https://stackoverflow.com/questions/30186611/php-dateformat-to-moment-js-format
    $replacements = array(
    /* Day / 'jS' => 'Do', /o doesn't exist on its own, so we find/replase jS only/ 'd' => 'DD', 'D' => 'ddd', 'j' => 'D', 'l' => 'dddd', 'N' => 'E', /'S' => 'o' - see jS/ 'w' => 'e', 'z' => 'DDD', / Week / 'W' => 'W', / Month / 'F' => 'MMMM', 'm' => 'MM', 'M' => 'MMM', 'n' => 'M', 't' => '#t', / days in the month => moment().daysInMonth(); / / Year / 'L' => '#L', / Leap year? => moment().isLeapYear(); / 'o' => 'YYYY', 'Y' => 'YYYY', 'y' => 'YY', / Time / 'a' => 'a', 'A' => 'A', 'B' => '', / Swatch internet time (.beats), no equivalent / 'g' => 'h', 'G' => 'H', 'h' => 'hh', 'H' => 'HH', 'i' => 'mm', 's' => 'ss', 'u' => 'SSSSSS', / microseconds / 'v' => 'SSS', / milliseconds (from PHP 7.0.0) / / Timezone / 'e' => '##T', / Timezone - deprecated since version 1.6.0 of moment.js, we'll use Intl.DateTimeFromat().resolvedOptions().timeZone instead. / 'I' => '##t', / Daylight Saving Time? => moment().isDST(); / 'O' => 'ZZ', 'P' => 'Z', 'T' => '#T', / deprecated since version 1.6.0 of moment.js, using GMT difference with colon to keep it shorter than full timezone / 'Z' => '###t', / time zone offset in seconds => moment().zone() * -60 : the negative is because moment flips that around; / / Full Date/Time / 'c' => 'YYYY-MM-DD[T]HH:mm:ssZ', / ISO 8601 / 'r' => 'ddd, DD MMM YYYY HH:mm:ss ZZ', / RFC 2822 */ 'U' => 'X',
    );
    // Converts escaped characters.
    foreach ($replacements as $from => $to) {
    $replacements['\' . $from] = '[' . $from . ']';
    $time_format = strtr($time_format, $replacements);
    }
    //fixing error
    if( $result === '#_EVENTDATES_LOCAL' ){
    $time_format = ( get_option('dbem_date_format') ) ? get_option('dbem_date_format'):get_option('date_format');
    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_date == $this->event_end_date ? $start_time : $this->end()->getTimestamp();
    if( empty($separator) ) $separator = get_option('dbem_dates_separator');
    }else{
    $time_format = ( get_option('dbem_time_format') ) ? get_option('dbem_time_format'):get_option('time_format');
    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_time == $this->event_end_time ? $start_time : $this->end()->getTimestamp();
    if( empty($separator) ) $separator = get_option('dbem_times_separator');
    }
    wp_enqueue_script('moment', '', array(), false, true); //add to footer if not already
    // start output
    ob_start();
    ?>
    <span class="em-date-momentjs" data-date-format="<?php echo esc_attr($time_format); ?>" data-date-start="<?php echo $start_time ?>" data-date-end="<?php echo $end_time ?>" data-date-separator="<?php echo esc_attr($separator); ?>">JavaScript Disabled</span>
    <?php
    $replace = ob_get_clean();
    }
    break;
    Thread Starter fjr9

    (@fjr9)

    Okay, final correction (I believe).

    Only

    if( $result === '#_EVENTDATES_LOCAL' ){
    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_date == $this->event_end_date ? $start_time : $this->end()->getTimestamp();
    }else{
    $start_time = $this->start()->getTimestamp();
    $end_time = $this->event_start_time == $this->event_end_time ? $start_time : $this->end()->getTimestamp();
    }

    should be outside the IF function, without the rest, or it will mess things up.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘_EVENTDATES _LOCAL{…} not retrieving data correctly’ is closed to new replies.