Skip to content

Fix weekday header mismatch when weekStart is not Sunday#23

Open
JacobBrooke95 wants to merge 1 commit intoliamcain:masterfrom
JacobBrooke95:fix/weekday-header-mismatch
Open

Fix weekday header mismatch when weekStart is not Sunday#23
JacobBrooke95 wants to merge 1 commit intoliamcain:masterfrom
JacobBrooke95:fix/weekday-header-mismatch

Conversation

@JacobBrooke95
Copy link

Summary

When weekStart is set to something other than Sunday (e.g., Monday), moment.weekdaysShort(true) doesn't reliably return days starting from the locale's first day of week. This causes the day labels in the calendar header to not match the actual day positions in the calendar grid.

For example, with weekStart: "monday", the calendar would display "Sun" in the first column but show Monday's dates underneath it.

The Fix

Instead of relying on moment.weekdaysShort(true), this fix manually rotates the weekdays array based on the locale's dow (day of week) setting:

export function getDaysOfWeek(..._args: unknown[]): string[] {
  const { moment } = window;
  const weekdaysShort = moment.weekdaysShort();
  const dow = moment.localeData()._week.dow;
  // Manually rotate array to start with locale's first day of week
  return [...weekdaysShort.slice(dow), ...weekdaysShort.slice(0, dow)];
}

Related Issue

Fixes liamcain/obsidian-calendar-plugin#346

Testing

Tested locally by modifying the compiled main.js in the calendar plugin with this fix. Confirmed that with weekStart: "monday":

  • The calendar header now correctly shows Mon, Tue, Wed, Thu, Fri, Sat, Sun
  • The day positions match the header labels
  • Saturday January 17, 2026 correctly displays as Saturday (not Sunday)

🤖 Generated with Claude Code

When weekStart is set to something other than Sunday (e.g., Monday),
moment.weekdaysShort(true) doesn't reliably return days starting from
the locale's first day of week. This causes the day labels in the
header to not match the actual day positions in the calendar grid.

This fix manually rotates the weekdays array based on the locale's
dow (day of week) setting.

Fixes liamcain/obsidian-calendar-plugin#346

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

When I change start day of the week from Sunday to Monday dates are set incorrectly

1 participant