Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ Copy the `team51-focal-point` folder to your `mu-plugins` directory.

## Changelog

### 2.1.3

- **Calendar grid alignment:** fixed month grid date placement when WordPress **Week Starts On** is set to Sunday (or any `start_of_week` other than Monday). Dates and events now appear under the correct weekday column.

### 2.1.2

- **Calendar loading UX:** added a loading skeleton while calendar month requests are in flight.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wpcomsp-simple-events",
"version": "2.1.2",
"version": "2.1.3",
"description": "A simple Gutenberg-first event management plugin that integrates with WooCommerce Box Office.",
"author": {
"name": "WordPress.com Special Projects Team",
Expand Down
6 changes: 3 additions & 3 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Simple Events Plugin bootstrap file.
*
* @since 1.0.0
* @version 2.1.2
* @version 2.1.3
* @author WordPress.com Special Projects
* @license GPL-3.0-or-later
*
Expand All @@ -14,7 +14,7 @@
* Description: Event management frontend for WooCommerce Box Office.
* Requires at least: 6.5
* Tested up to: 6.9
* Version: 2.1.2
* Version: 2.1.3
* Requires PHP: 8.0
* Author: WordPress.com Special Projects
* Author URI: https://wpspecialprojects.wordpress.com
Expand All @@ -32,7 +32,7 @@
function_exists( 'get_plugin_data' ) || require_once ABSPATH . 'wp-admin/includes/plugin.php';
define( 'SE_METADATA', get_plugin_data( __FILE__, false, false ) );

define( 'SE_VERSION', '2.1.2' );
define( 'SE_VERSION', '2.1.3' );
define( 'SE_BASENAME', plugin_basename( __FILE__ ) );
define( 'SE_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'SE_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
Expand Down
58 changes: 25 additions & 33 deletions src/classes/class-se-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function register_routes(): void {
* @param string $format The display format for the days of the week.
*
* @return array Days of the week.
**@category Events
* *@category Events
*/
public function simple_events_get_days_of_week( $format = null ) {
global $wp_locale;
Expand Down Expand Up @@ -442,56 +442,48 @@ private function get_events_by_date( $date ): array {


/**
* Get the start day based on the given date and start of the week.
* Get the first calendar cell for the month (weeks align to WordPress start of week).
*
* @param mixed $date The date for which to calculate the start day.
* @param integer $start_of_week The start of the week (0-6, where 0 is Sunday).
* @param mixed $date First day of the month to display.
* @param integer $start_of_week Attribute `start_of_week` option: 0 = Sunday through 6 = Saturday.
*
* @return DateTime The start day based on the given date and start of the week.
* @return DateTime First grid day at 00:00:00.
*/
private function get_start_day( $date, $start_of_week ) {
$start_date = clone $date;
$start_day_interval = 0;
$start_date = clone $date;
$start_date->setTime( 0, 0, 0 );

$start_day_week_position = $date->format( 'w' );
$w = (int) $start_date->format( 'w' );
$days_back_to_sow = ( $w - (int) $start_of_week + 7 ) % 7;

if ( $start_of_week > 0 && 0 === intval( $start_day_week_position ) ) {
$start_day_week_position = 7;
}

if ( 0 !== intval( $start_day_week_position ) ) {
$start_day_interval = abs( 1 - $start_day_week_position );
}

return $start_date->sub( new DateInterval( 'P' . $start_day_interval . 'D' ) );
return 0 === $days_back_to_sow
? $start_date
: $start_date->sub( new DateInterval( 'P' . $days_back_to_sow . 'D' ) );
}


/**
* Get the end day based on the given date and start of the week.
* Get the last day shown in the grid for the month (inclusive), at 23:59:59.
*
* @param Date $date The date to calculate the end day from.
* @param integer $start_of_week The start of the `week (0-6, where 0 is Sunday).
* @param mixed $date Any day in the month (used to find last day of month).
* @param integer $start_of_week Attribute `start_of_week` option: 0 = Sunday through 6 = Saturday.
*
* @return DateTime The end day based on the given date and start of the week.
* @return DateTime End boundary for the period.
*/
private function get_end_day( $date, $start_of_week ) {
$end_date = clone $date;
$last_day_interval = 0;
$end_date = clone $date;
$end_date->modify( 'last day of this month' );
$end_date->setTime( 0, 0, 0 );

$last_day_of_month = $end_date->modify( 'last day of this month' );
$last_day_week_position = $last_day_of_month->format( 'w' );
$w = (int) $end_date->format( 'w' );
$offset_in_row = ( $w - (int) $start_of_week + 7 ) % 7;
$days_to_add = 6 - $offset_in_row;

if ( $start_of_week > 0 && 0 === intval( $last_day_week_position ) ) {
$last_day_week_position = 7;
if ( $days_to_add > 0 ) {
$end_date->add( new DateInterval( 'P' . $days_to_add . 'D' ) );
}

if ( 0 !== intval( $last_day_week_position ) ) {
$last_day_interval = 7 - $last_day_week_position;
}

$end_date->setTime( 23, 59, 59 );

return $end_date->add( new DateInterval( 'P' . $last_day_interval . 'D' ) );
return $end_date;
}
}
Loading