Event Calendar - weekly view

93 posts by 3 authors in: Forums > CMS Builder
Last Post: Yesterday at 6:53am   (RSS)

By MercerDesign - Yesterday at 4:15am - edited: Yesterday at 4:23am

Hi, I did a CMS upgrade this morning to fix another issue but now any events after the 28th of December are not showing, can you help please? It only seems to be a problem on the week view.

By Djulia - Yesterday at 5:30am - edited: Yesterday at 6:47am

Hi MercerDesign,

The issue appears to stem from improper handling of dates that span across two years in the week view, particularly during the transition from week 52/53 of one year to week 1 of the following year. This can lead to inconsistencies in the values generated for $week_start, $start, and $end.

Here is a corrected version for the query in the week view:

// Creates a date for the start of the given week (ISO year and ISO week)
$date = new DateTime();
$date->setISODate($year, $week); // Sets the date using the ISO year and week

// Format for the start and end of the week
$week_start = $date->format($FORMAT_START); // First day of the week
$start = $date->modify('-1 week')->format($FORMAT_START); // Start of the previous week
$end = $date->modify('+2 weeks -1 day')->format($FORMAT_END); // End of the following week

// SQL query to find events overlapping this period
$query = "start_date <= '$end' AND end_date >= '$start'";

Thanks,
Djulia

Attachments:

calendar.php 21K