Skip to content

Fix calendar grid alignment when doesn't start on Monday#76

Merged
gin0115 merged 3 commits into
a8cteam51:trunkfrom
jbouganim:fix/calendar-dow
Jun 10, 2026
Merged

Fix calendar grid alignment when doesn't start on Monday#76
gin0115 merged 3 commits into
a8cteam51:trunkfrom
jbouganim:fix/calendar-dow

Conversation

@jbouganim

@jbouganim jbouganim commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This issue is live on https://thepocketnyc.com/calendar/grid/

Changes proposed in this Pull Request

  • Fix get_start_day() and get_end_day() in class-se-calendar.php so the month grid respects WordPress start_of_week for all values (0–6), not just Monday.
  • Replace Monday-only offset math (abs(1 - w) / 7 - w) with ( w - start_of_week + 7 ) % 7 so dates appear under the correct weekday column.
  • Normalize grid boundaries to midnight before calculating offsets.

Before: With Week Starts On → Sunday, a month whose 1st falls on Monday (e.g. June 2026) showed the 1st under the Sunday column — headers were correct but dates were shifted.

After: Grid cells align with weekday headers for both Sunday and Monday week starts.

Correct:

Screenshot 2026-06-09 at 12 23 17 PM

Incorrect:

June 9, 26 is a not a Monday.

Screenshot 2026-06-09 at 12 23 00 PM

Testing instructions

  1. Add a page with the Simple Events Calendar block.
  2. Ensure at least one event exists in the month under test.

Sunday week start (start_of_week = 0)

  • Go to Settings → General → Week Starts On → Sunday.
  • Open the calendar to June 2026 (1st is a Monday).
  • Confirm column headers are Sun–Sat.
  • Confirm June 1 appears under Monday, not Sunday.
  • Confirm May 31 (Sunday) appears in the leading cell of the first row.
  • Confirm events render on the correct calendar dates.

Monday week start (start_of_week = 1)

  • Set Week Starts On → Monday.
  • Reload June 2026.
  • Confirm June 1 appears under Monday (regression check — this case worked before).

Month navigation

  • Use prev/next month controls (initial render and AJAX).
  • Confirm leading/trailing days from adjacent months still align correctly.
  • Confirm events stay on the correct dates after navigation.

Mentions #
@gin0115 @tommusrhodus

Summary by CodeRabbit

  • Bug Fixes

    • Fixed calendar grid alignment so dates and events appear under the correct weekday when the week start is set to Sunday or any day other than Monday.
  • Chores

    • Version bumped to 2.1.3.
  • Documentation

    • Changelog updated to reflect the 2.1.3 fix.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7fc051f2-f661-4d7e-921b-417168879ce0

📥 Commits

Reviewing files that changed from the base of the PR and between d28735b and 8f5e632.

📒 Files selected for processing (1)
  • src/classes/class-se-calendar.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/classes/class-se-calendar.php

Walkthrough

This PR fixes calendar month grid alignment when WordPress "Week Starts On" is configured to a value other than Monday. The get_start_day() and get_end_day() methods in SE_Calendar were rewritten to use modular arithmetic with PHP's weekday format and the WordPress start_of_week option, ensuring grid boundaries align dates and events under the correct weekday columns. Version metadata was bumped to 2.1.3 across package.json, plugin headers, the runtime constant, and the README changelog.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the primary fix in the changeset: correcting calendar grid alignment when the week doesn't start on Monday by adjusting start_of_week calculations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/classes/class-se-calendar.php`:
- Line 448: Update the `@param` docblock for $start_of_week in
class-se-calendar.php: change the type from "int" to "integer" and start the
parameter description with a capital letter or rephrase it (for example:
"WordPress `start_of_week` option: 0 = Sunday through 6 = Saturday.") so the
comment begins with a capitalized word and satisfies PHPCS.
- Line 469: Update the docblock for the parameter $start_of_week in the
SE_Calendar class (where the `@param` currently reads "int $start_of_week
`start_of_week` option: 0 = Sunday through 6 = Saturday.") to use the word
"integer" instead of "int" and start the parameter description with a capital
letter (e.g., "Start_of_week `start_of_week` option: ..." or better "Start of
week `start_of_week` option: ..."), ensuring the `@param` line reads "`@param`
integer $start_of_week Start of week `start_of_week` option: 0 = Sunday through
6 = Saturday." to satisfy PHPCS.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9311a45b-4033-451e-bcf4-681c527aa9bc

📥 Commits

Reviewing files that changed from the base of the PR and between 1289ce6 and d28735b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • README.md
  • package.json
  • plugin.php
  • src/classes/class-se-calendar.php

Comment thread src/classes/class-se-calendar.php Outdated
Comment thread src/classes/class-se-calendar.php Outdated
@gin0115 gin0115 merged commit 5572c9b into a8cteam51:trunk Jun 10, 2026
8 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants