Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

844 B
Raw Blame
import { addDays, isSameDay, startOfDay } from "date-fns";
import type { AssignedTask } from "@/fetchers/task/get-assigned-tasks";

export type WeekDay = {
  date: Date;
  isToday: boolean;
  isPast: boolean;
  tasks: AssignedTask[];
};

const DAYS_BEFORE = 3;
const DAYS_AFTER = 3;

// Centred on today: the days just missed matter as much as the ones coming up.
export function buildWeek(tasks: AssignedTask[], now = new Date()): WeekDay[] {
  const today = startOfDay(now);

  return Array.from({ length: DAYS_BEFORE + DAYS_AFTER + 1 }, (_, index) => {
    const offset = index - DAYS_BEFORE;
    const date = addDays(today, offset);

    return {
      date,
      isToday: offset === 0,
      isPast: offset < 0,
      tasks: tasks.filter(
        (task) => task.dueDate && isSameDay(new Date(task.dueDate), date),
      ),
    };
  });
}