Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Commit

Permalink
fix calendar days being off by 1
Browse files Browse the repository at this point in the history
  • Loading branch information
rudotriton committed Nov 1, 2020
1 parent dfca45a commit fbfd3ae
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function buildCalendarView(stack) {
dateFormatter.dateFormat = "MMMM";

// if calendar is on a small widget make it a bit smaller to fit
const spacing = config.widgetFamily === "small" ? 18 : 20;
const spacing = config.widgetFamily === "small" ? 18 : 19;

// Current month line
const monthLine = rightStack.addStack();
Expand All @@ -160,9 +160,6 @@ async function buildCalendarView(stack) {
font: Font.boldSystemFont(13),
});

// between the month name and the week calendar
rightStack.addSpacer(5);

const calendarStack = rightStack.addStack();
calendarStack.spacing = 2;

Expand Down Expand Up @@ -286,18 +283,22 @@ function buildMonthVertical() {
let index = 1;
let offset = 1;

// weekdays are 0 indexed starting with sunday
let firstDay = firstOfMonth.getDay() !== 0 ? firstOfMonth.getDay() : 7;

if (startWeekOnSunday) {
month.unshift(["S"]);
index = 0;
offset = 0;
firstDay = firstDay % 7;
} else {
month.push(["S"]);
}

let dayStackCounter = 0;

// fill with empty slots
for (; index < firstOfMonth.getDay(); index += 1) {
for (; index < firstDay; index += 1) {
month[index - offset].push(" ");
dayStackCounter = (dayStackCounter + 1) % 7;
}
Expand Down

0 comments on commit fbfd3ae

Please sign in to comment.