Files
Nexus/packages/application/src/use-cases/dashboard/shared.ts
T
Hartmut 1df208dbcc feat(timeline): add pulse animation for in-flight drag mutations
Allocation bars that have active optimistic overrides (post-drag,
awaiting server confirmation) now pulse subtly via animate-pulse.
The pending set is derived from the existing optimisticAllocations
map keys, requiring no additional state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 13:28:46 +02:00

42 lines
1.2 KiB
TypeScript

export { MILLISECONDS_PER_DAY } from "@capakraken/shared";
import { MILLISECONDS_PER_DAY } from "@capakraken/shared";
export function calculateInclusiveDays(startDate: Date, endDate: Date): number {
return (endDate.getTime() - startDate.getTime()) / MILLISECONDS_PER_DAY + 1;
}
export function calculateAllocationHours(input: {
startDate: Date;
endDate: Date;
hoursPerDay: number;
}): number {
return input.hoursPerDay * calculateInclusiveDays(input.startDate, input.endDate);
}
export function getMonthBucketKey(date: Date): string {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
}
export function getWeekBucketKey(date: Date): string {
const weekStart = new Date(date);
const day = weekStart.getDay();
const diff = weekStart.getDate() - day + (day === 0 ? -6 : 1);
weekStart.setDate(diff);
return weekStart.toISOString().slice(0, 10);
}
export function getAverageDailyAvailabilityHours(
availability: Record<string, number | null | undefined> | null | undefined,
): number {
if (!availability) {
return 0;
}
const totalWeeklyHours = Object.values(availability).reduce(
(sum: number, hours) => sum + (hours ?? 0),
0,
);
return totalWeeklyHours / 5;
}