getTimestamp())), $dias)){ $dDia->modify('+1 day'); } return $dDia; } public static function horas($hrInicio, $hrFin, $tipo){ if (empty($hrInicio)) $hrs = 'Todo el día'; else { if (strlen($hrInicio) > 5) $hrs = substr ($hrInicio, 0, 5); else $hrs = $hrInicio; if (!empty($hrFin)) { if (strlen($hrFin) > 5) $hrFin = substr ($hrFin, 0, 5); switch ($tipo) { case '|': $hrs .= '|' . $hrFin; break; case 'a': $hrs .= ' a ' .$hrFin; break; case '-': default: $hrs .= ' - ' . $hrFin; break; } } $hrs .= ' h.'; } return $hrs; } public static function romanizaMes($mes){ return self::$meses[$mes]; } public static function abreviaturaMes($mes){ return self::$mesesShort[$mes]; } public static function romanizaFecha($fecha, $anio = false){ if (is_string($fecha)) $fecha = new DateTimeImmutable($fecha); if ($anio) return $fecha->format('j') . ' de ' . self::romanizaMes(intval($fecha->format('n'))) . ' de ' . $fecha->format('Y'); else return $fecha->format('j') . ' de ' . self::romanizaMes(intval($fecha->format('n'))); } public static function estandarizaDia($dia1, $dia2, $tipo, $anio = false) { if (is_string($dia1)) $dia1 = new DateTimeImmutable($dia1); if (is_string($dia2)) $dia2 = new DateTimeImmutable($dia2); $pre = ""; $conjuncion = ', '; $tipo = strtoupper($tipo); switch ($tipo){ case 'ULTIMOS': $pre = ''; $conjuncion = ' y '; break; case 'RANGO': $pre = 'Del '; $conjuncion = ' al '; break; case 'ALTERNADOS': $pre = '' ; $conjuncion = ', '; break; } $rango = ''; if ($dia1->format('Y') === $dia2->format('Y')){ if ($dia1->format('n') === $dia2->format('n')){ $rango .= $pre . $dia1->format('j') . $conjuncion; if ($tipo != 'ALTERNADOS') $rango .= self::romanizaFecha($dia2, $anio); } else { $rango .= $pre . $dia1->format('j') . ' de ' . self::romanizaMes(intval($dia1->format('n'))) . $conjuncion; if ($tipo != 'ALTERNADOS') $rango .= self::romanizaFecha($dia2, $anio); } } else { $rango .= $pre . self::romanizaFecha($dia1, $anio) . $conjuncion; if ($tipo != 'ALTERNADOS') $rango .= self::romanizaFecha($dia2, $anio); } return $rango; } public static function dosDigitos($num) { // if is of type string parse int if (is_string($num)) $num = intval($num); if ($num < 10) return '0' . $num; else return $num; } public static function fechaRango($fecha1, $fecha2, $separador = '/') { $fecha = ''; if (!empty($fecha1)){ $fecha1 = explode($separador, $fecha1); if (count($fecha1) > 1 && (intval($fecha1[1]) > 0 && intval($fecha1[1]) < 13)) $fecha = ucfirst(self::abreviaturaMes(intval($fecha1[1]))) . ' ' . $fecha1[0]; if ($fecha2 == null) $fecha .= ' - Actualidad'; else { if (!empty($fecha2)) { $fecha2 = explode($separador, $fecha2); if (count($fecha2) > 1 && (intval($fecha2[1]) > 0 && intval($fecha2[1]) < 13)) $fecha .= ' - ' . ucfirst(self::abreviaturaMes(intval($fecha2[1]))) . ' ' . $fecha2[0]; } } } return $fecha; } public static function validaFormatoFecha($fecha){ if (str_contains('/', $fecha)) $fecha = DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d'); return $fecha; } }