8 string $format =
'day,dd.mm.yyyy',
10 ?DateTime
$base =
null
18 $base =
new DateTime(
'today');
27 $is_workday =
function(DateTime $d): bool {
29 $w = (int)$d->format(
'N');
31 $maxWorkday = (int)
dbx()->get_config(
'myLKW',
'workdays');
36 if ($w > $maxWorkday) {
47 $next_workday =
function(DateTime $d) use ($is_workday): DateTime {
51 }
while (!$is_workday($d));
55 $prev_workday =
function(DateTime $d) use ($is_workday): DateTime {
59 }
while (!$is_workday($d));
68 for ($i = 0; $i < $offset; $i++) {
74 for ($i = 0; $i < abs($offset); $i++) {
83 $dias_full = [
'domingo',
'lunes',
'martes',
'miércoles',
'jueves',
'viernes',
'sábado'];
84 $dias_short = [
'Dom',
'Lun',
'Mar',
'Mié',
'Jue',
'Vie',
'Sáb'];
87 1=>
'enero',
'febrero',
'marzo',
'abril',
'mayo',
'junio',
88 'julio',
'agosto',
'septiembre',
'octubre',
'noviembre',
'diciembre'
95 if (strpos($format,
'~~') !==
false) {
97 $fmt = str_replace(
'~~',
'',$format);
99 $format_date =
function(DateTime $d) use ($fmt, $dias_full, $dias_short, $meses_full):
string {
103 $out = str_replace(
'day', $dias_full[(
int)$d->format(
'w')],
$out);
104 $out = str_replace(
'dy', $dias_short[(
int)$d->format(
'w')],
$out);
106 $out = str_replace(
'dd', $d->format(
'd'),
$out);
107 $out = str_replace(
'mm', $d->format(
'm'),
$out);
108 $out = str_replace(
'yyyy', $d->format(
'Y'),
$out);
110 $out = str_replace(
'month', $meses_full[(
int)$d->format(
'n')],
$out);
115 $start = clone
$base;
116 $end = $next_workday($start);
118 return $format_date($start) .
' ~~ ' . $format_date($end);
125 $format_date =
function(DateTime $d) use ($format, $dias_full, $dias_short, $meses_full):
string {
129 $out = str_replace(
'day', $dias_full[(
int)$d->format(
'w')],
$out);
130 $out = str_replace(
'dy', $dias_short[(
int)$d->format(
'w')],
$out);
132 $out = str_replace(
'dd', $d->format(
'd'),
$out);
133 $out = str_replace(
'mm', $d->format(
'm'),
$out);
134 $out = str_replace(
'yyyy', $d->format(
'Y'),
$out);
136 $out = str_replace(
'month', $meses_full[(
int)$d->format(
'n')],
$out);
141 return $format_date(
$base);