commit melhorias sgf
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Sgc;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Generator;
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class CalendarDimension
|
||||
{
|
||||
/** Weekdays are a calendar approximation, not an official holiday calendar. */
|
||||
public static function days(int $startYear, int $years): Generator
|
||||
{
|
||||
if ($startYear < 1 || $years < 1 || $years > 100 || $startYear + $years > 10000) throw new InvalidArgumentException('Invalid calendar interval.');
|
||||
$months = [1=>'Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];
|
||||
$weekdays = [1=>'Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'];
|
||||
$date = new DateTimeImmutable(sprintf('%04d-01-01', $startYear), new DateTimeZone('Africa/Maputo'));
|
||||
while ((int)$date->format('Y') < $startYear + $years) {
|
||||
$month = (int)$date->format('n'); $weekday = (int)$date->format('N');
|
||||
yield ['data_id'=>(int)$date->format('Ymd'), 'data_completa'=>$date->format('Y-m-d'),
|
||||
'dia_semana'=>$weekday, 'nome_dia_semana'=>$weekdays[$weekday], 'dia_mes'=>(int)$date->format('j'),
|
||||
'mes'=>$month, 'nome_mes'=>$months[$month], 'trimestre'=>intdiv($month-1,3)+1,
|
||||
'ano'=>(int)$date->format('Y'), 'ano_mes'=>$date->format('Y-m'),
|
||||
'eh_dia_util'=>$weekday<=5, 'eh_feriado'=>false, 'semestre'=>$month<=6?1:2];
|
||||
$date = $date->modify('+1 day');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user