PHP code example of arifur9993 / attendance-engine

1. Go to this page and download the library: Download arifur9993/attendance-engine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arifur9993 / attendance-engine example snippets


use Arifur9993\AttendanceEngine\Engine;
use Arifur9993\AttendanceEngine\Types\Punch;
use Arifur9993\AttendanceEngine\Types\ShiftConfig;
use Arifur9993\AttendanceEngine\Types\ResolveDayInput;

$result = Engine::resolveDay(new ResolveDayInput(
    date: '2026-06-01',
    punches: [
        new Punch(at: '2026-06-01T08:57:00+06:00'),
        new Punch(at: '2026-06-01T18:04:00+06:00'),
    ],
    shift: new ShiftConfig(start: '09:00', end: '18:00', graceIn: 10),
));

echo $result->status;         // 'present'
echo $result->workedMinutes;  // 547
echo $result->lateByMinutes;  // 0
echo $result->otMinutes;      // 4

// JSON-ready for your API
return response()->json($result);   // implements JsonSerializable

use Arifur9993\AttendanceEngine\Engine;
use Arifur9993\AttendanceEngine\Types\{ResolveRangeInput, ShiftConfig, AttendancePolicy};

$nineToSix = fn (string $date): ?ShiftConfig =>
    in_array(date('w', strtotime($date)), [0, 6], true)
        ? null                                              // weekend off
        : new ShiftConfig(start: '09:00', end: '18:00', graceIn: 10);

$range = Engine::resolveRange(new ResolveRangeInput(
    from: '2026-06-01',
    to:   '2026-06-30',
    punches: $monthOfPunches,         // flat list — auto-bucketed onto duty-dates
    shiftFor: $nineToSix,
    policy: new AttendancePolicy(tzOffsetMinutes: 360),
    holidays: ['2026-06-15' => true],
));

$summary = Engine::summarize($range);
echo $summary->workedHours();   // 162.5
echo $summary->daysLate;         // 2
echo $summary->daysAbsent;       // 1

use Arifur9993\AttendanceEngine\Engine;
use Arifur9993\AttendanceEngine\Types\ShiftConfig;

$day   = new ShiftConfig(start: '09:00', end: '18:00');
$night = new ShiftConfig(start: '22:00', end: '06:00');

$roster = Engine::generateRoster(
    from: '2026-06-01',
    to:   '2026-06-07',
    pattern: [
        0 => null,    // Sun off
        1 => $day, 2 => $day, 3 => $night, 4 => $night,
        5 => $day, 6 => null, // Sat off
    ],
);

// Now pass it through:
$shiftFor = fn (string $d) => $roster[$d] ?? null;

use Arifur9993\AttendanceEngine\Engine;

$clean = Engine::applyRounding($rawPunches, unitMinutes: 5, strategy: 'nearest');
// 08:57:23 → 08:55:00,  18:04:11 → 18:05:00

$result = Engine::resolveDay(/* ... */ punches: $clean);

$violations = Engine::evaluateBreakCompliance($day, [
    'minBreakMinutes'    => 30,
    'afterWorkedMinutes' => 300,   // 5 hours
]);

if ($violations) {
    Log::warning('Break compliance', ['employee' => $id, 'issues' => $violations]);
}

// app/Services/AttendanceService.php
use Arifur9993\AttendanceEngine\Engine;

class AttendanceService
{
    public function dayFor(Employee $e, string $date): DayResult
    {
        return Engine::resolveDay(new ResolveDayInput(
            date:    $date,
            punches: $e->punches()->forDate($date)->toEngineList(),
            shift:   $e->shiftFor($date)->toEngineConfig(),
            policy:  app(AttendancePolicy::class),
        ));
    }
}
bash
git clone https://github.com/arifur9993/attendance-engine-php.git
cd attendance-engine-php
composer install
composer test       # Pest
composer analyse    # PHPStan level 8
composer format     # Pint