Files
SIRH/src/Service/Exercise/ExerciseYearResolver.php
T
tristan abdaf809f8
Auto Tag Develop / tag (push) Has been cancelled
Gestion du changement de type de contrat + correction du calcule des RTT sur un contrat qui commence en milieu de semaine (#19)
| Numéro du ticket | Titre du ticket |
|------------------|-----------------|
|                  |                 |

## Description de la PR

## Modification du .env

## Check list

- [x] Pas de régression
- [x] TU/TI/TF rédigée
- [x] TU/TI/TF OK
- [x] CHANGELOG modifié

Reviewed-on: #19
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
2026-05-22 06:42:33 +00:00

28 lines
688 B
PHP

<?php
declare(strict_types=1);
namespace App\Service\Exercise;
use DateTimeImmutable;
final readonly class ExerciseYearResolver
{
/**
* Convert a date to its leave/RTT exercise year.
*
* - Forfait: calendar year (Jan→Dec) — returns $date.Y.
* - Non-forfait: leave year (Juin N-1 → Mai N) — returns $date.Y+1 if month >= 6, else $date.Y.
*/
public function forDate(DateTimeImmutable $date, bool $isForfait = false): int
{
if ($isForfait) {
return (int) $date->format('Y');
}
return (int) $date->format('n') >= 6
? (int) $date->format('Y') + 1
: (int) $date->format('Y');
}
}