gitshark

Clone repository

git clone https://git.vilip.de/git/vilip/taskflow.git
git clone git@git.vilip.de:vilip/taskflow.git
/**
 * Calendar grid helpers
 *
 * Pure logic for laying out a month as weeks, so the calendar grid can be
 * rendered as fixed 7-column rows (avoiding sub-pixel width rounding that
 * would otherwise wrap the last column).
 */

/**
 * Build the weeks of a month as rows of 7 cells. Each cell is the day number
 * (1-based) or `null` for padding before the first / after the last day.
 * Week starts on Sunday (index 0), matching the weekday headers.
 *
 * @param year  Full year, e.g. 2026
 * @param month Month index, 0 = January … 11 = December
 */
export function buildCalendarWeeks(year: number, month: number): (number | null)[][] {
  const startingDayOfWeek = new Date(year, month, 1).getDay(); // 0 = Sunday
  const daysInMonth = new Date(year, month + 1, 0).getDate();

  const cells: (number | null)[] = [];
  for (let i = 0; i < startingDayOfWeek; i++) {
    cells.push(null);
  }
  for (let day = 1; day <= daysInMonth; day++) {
    cells.push(day);
  }
  while (cells.length % 7 !== 0) {
    cells.push(null);
  }

  const weeks: (number | null)[][] = [];
  for (let i = 0; i < cells.length; i += 7) {
    weeks.push(cells.slice(i, i + 7));
  }
  return weeks;
}

Keyboard shortcuts

?Show this help
g hGo home
EscClose dialog