Okay
  Public Ticket #2583880
Displaying only the Time of an event
Closed

Comments

  •  2
    Santiago started the conversation

    I'd like to display the Time of an event (e.g. "8:00 PM to 00:45 AM") in the Map (w/list) view.

    I noticed that the variable 'stec_replace_date' displays a string like "Oct 28 2020 20:00 - Oct 29 00:45". Could I replace the value of this variable using a function on the functions.php, so that I don't touch the page template? If not, what would be the most efficient / less ugly way to accomplish this?

    Thanks!

  •  783
    Zhivko replied

    Try this mod:

    add_action('wp_footer', function() {
        global $post;
        if (!is_a($post, 'WP_Post') || !has_shortcode($post->post_content, 'stachethemes_ec')) {
            return;
        }
        ?>
        <script type="text/javascript">
            (function ($) {             $(function () {                 if (typeof $.stecExtend === 'undefined') {
                        return;
                    }                 var defaultDateTimeFormat = '';                 $.stecExtend(function (m) {
                        defaultDateTimeFormat = m.glob.options.general_settings.date_format;
                    });                 $.stecExtend(function (m) {
                        if (m.glob.options.view === 'map') {
                            m.glob.options.general_settings.date_format = 'H:mm A';
                        } else {
                            m.glob.options.general_settings.date_format = defaultDateTimeFormat;
                        }
                    }, 'onLayoutSet');
                });
            })(window.jQuery);
        </script>
        <?php
    });



    Stachethemes Developer

  •  2
    Santiago replied

    Excellent, thank you sir! I'll play with this :)

  •   Santiago replied privately
  •  783
    Zhivko replied

    It turns out this filter overrides the date format only and the time is attached after... I'll have to revisit this code at some point because even I am starting to wonder why it is done this way.

    Meanwhile use this filter instead:

    add_action('wp_footer', function() {
        global $post;
        if (!is_a($post, 'WP_Post') || !has_shortcode($post->post_content, 'stachethemes_ec')) {
            return;
        }
        ?>
        <script type="text/javascript">
            (function ($) {
                $(function () {
                    if (typeof $.stecExtend === 'undefined') {
                        return;
                    }
                    $.stecExtend(function (m) {
                        m.$instance.on('stecBeforeReturnEventPreviewHtml', function (a, data) {
                            
                            var preview, event, sd, ed, html, timeFormat, timeString = [];
                            
                            if (m.glob.options.view === 'map') {
                                event = data.event;
                                preview = $(data.temp.EventPreviewHtml);
                                
                                timeFormat = 'H:mm A';
                                
                                sd = moment.tz(event.start_date, event.timezone);
                                ed = moment.tz(event.end_date, event.timezone);
                                
                                timeString.push(sd.format(timeFormat));
                                
                                if (event.all_day !== 1) {
                                    timeString.push(ed.format(timeFormat));
                                }
                                
                                html = '<i class="fas fa-clock"></i>' + timeString.join(' - ');
                                preview.find('.stec-layout-event-preview-left-text-date').html(html);
                                data.temp.EventPreviewHtml = preview.get(0).outerHTML;
                            }
                        });
                    });
                });
            })(window.jQuery);
        </script>
        <?php
    });

    Stachethemes Developer

  •  2
    Santiago replied

    Excellent, thanks!