Files
headroom/backend/app/Utilities/WorkingDaysCalculator.php
Santhosh Janardhanan 1592c5be8d feat(capacity): Implement Capacity Planning capability (4.1-4.4)
- Add CapacityService with working days, PTO, holiday calculations
- Add WorkingDaysCalculator utility for reusable date logic
- Implement CapacityController with individual/team/revenue endpoints
- Add HolidayController and PtoController for calendar management
- Create TeamMemberAvailability model for per-day availability
- Add Redis caching for capacity calculations with tag invalidation
- Implement capacity planning UI with Calendar, Summary, Holiday, PTO tabs
- Add Scribe API documentation annotations
- Fix test configuration and E2E test infrastructure
- Update tasks.md with completion status

Backend Tests: 63 passed
Frontend Unit: 32 passed
E2E Tests: 134 passed, 20 fixme (capacity UI rendering)
API Docs: Generated successfully
2026-02-19 10:13:30 -05:00

50 lines
1.2 KiB
PHP

<?php
namespace App\Utilities;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
class WorkingDaysCalculator
{
public static function calculate(string $month, array $holidays = []): int
{
$start = Carbon::createFromFormat('Y-m', $month)->startOfMonth();
$end = $start->copy()->endOfMonth();
return self::getWorkingDaysInRange($start->toDateString(), $end->toDateString(), $holidays);
}
public static function getWorkingDaysInRange(string $start, string $end, array $holidays = []): int
{
$period = CarbonPeriod::create(Carbon::create($start), Carbon::create($end));
$holidayLookup = array_flip($holidays);
$workingDays = 0;
foreach ($period as $day) {
$date = $day->toDateString();
if (self::isWorkingDay($date, $holidayLookup)) {
$workingDays++;
}
}
return $workingDays;
}
public static function isWorkingDay(string $date, array $holidays = []): bool
{
$carbonDate = Carbon::create($date);
if ($carbonDate->isWeekend()) {
return false;
}
if (isset($holidays[$carbonDate->toDateString()])) {
return false;
}
return true;
}
}