123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- class Fechas {
- public static function obtenerDias($dias){
- $temp = '';
- for($cont = 0; $cont < count($dias); $cont++){
- if($dias[$cont])
- $temp .= ($cont + 1) . '-';
- }
- $dias = [];
- $temp = substr($temp, 0, strlen($temp)-1);
- $temp = explode('-',$temp);
- foreach ($temp as $t){
- if (intval($t) == 7)
- array_push ($dias,0);
- else
- array_push ($dias,intval($t));
- }
- sort($dias,SORT_NUMERIC);
- return $dias;
- }
- public static function obtenerDiasRepetidos($dDia, $dias){
- while (!in_array(intval(date('w', $dDia->getTimestamp())), $dias)){
- $dDia->modify('+1 day');
- }
- return $dDia;
- }
- public static function horas($hrInicio, $hrFin, $hrTermino){
- $hrs = [];
- $hrs[0] = ' '.$hrInicio;
- $hrs[1] = $hrInicio;
- if ($hrTermino){
- $hrs[0] .= ' - '.$hrFin;
- $hrs[1] .= '|'.$hrFin;
- }
- $hrs[0] .= ' hrs.';
- return $hrs;
- }
- public static function romanizaMes($mes){
- $meses = ['', 'enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre' ];
- return $meses[$mes];
- }
- public static function romanizaFecha($fecha){
- return $fecha->format('j') . ' de ' . self::romanizaMes(intval($fecha->format('n'))) . ' de ' . $fecha->format('Y');
- }
- public static function estandarizaDia($dia1, $dia2, $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);
- }
- else {
- $rango .= $pre . $dia1->format('j') . ' de ' . self::romanizaMes(intval($dia1->format('n'))) . $conjuncion;
- if ($tipo != 'alternados')
- $rango .= self::romanizaFecha($dia2);
- }
- }
- else {
- $rango .= $pre . self::romanizaFecha($dia1) . $conjuncion;
- if ($tipo != 'alternados')
- $rango .= self::romanizaFecha($dia2);
- }
- return $rango;
- }
-
- public static function dosDigitos($num){
- if ($num < 10)
- return '0' . $num;
- else
- return $num;
- }
- }
|