Fechas.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class Fechas {
  3. public static function obtenerDias($dias){
  4. $temp = '';
  5. for($cont = 0; $cont < count($dias); $cont++){
  6. if($dias[$cont])
  7. $temp .= ($cont + 1) . '-';
  8. }
  9. $dias = [];
  10. $temp = substr($temp, 0, strlen($temp)-1);
  11. $temp = explode('-',$temp);
  12. foreach ($temp as $t){
  13. if (intval($t) == 7)
  14. array_push ($dias,0);
  15. else
  16. array_push ($dias,intval($t));
  17. }
  18. sort($dias,SORT_NUMERIC);
  19. return $dias;
  20. }
  21. public static function obtenerDiasRepetidos($dDia, $dias){
  22. while (!in_array(intval(date('w', $dDia->getTimestamp())), $dias)){
  23. $dDia->modify('+1 day');
  24. }
  25. return $dDia;
  26. }
  27. public static function horas($hrInicio, $hrFin, $hrTermino){
  28. $hrs = [];
  29. $hrs[0] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$hrInicio;
  30. $hrs[1] = $hrInicio;
  31. if ($hrTermino){
  32. $hrs[0] .= ' - '.$hrFin;
  33. $hrs[1] .= '|'.$hrFin;
  34. }
  35. $hrs[0] .= ' hrs.';
  36. return $hrs;
  37. }
  38. public static function romanizaMes($mes){
  39. $meses = ['', 'enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre' ];
  40. return $meses[$mes];
  41. }
  42. public static function romanizaFecha($fecha){
  43. return $fecha->format('j') . ' de ' . self::romanizaMes(intval($fecha->format('n'))) . ' de ' . $fecha->format('Y');
  44. }
  45. public static function estandarizaDia($dia1, $dia2, $tipo){
  46. switch ($tipo){
  47. case 'ultimos':
  48. $pre = '';
  49. $conjuncion = ' y ';
  50. break;
  51. case 'rango':
  52. $pre = 'Del ';
  53. $conjuncion = ' al ';
  54. break;
  55. case 'alternados':
  56. $pre = '';
  57. $conjuncion = ', ';
  58. break;
  59. }
  60. $rango = '';
  61. if ($dia1->format('Y') === $dia2->format('Y')){
  62. if ($dia1->format('n') === $dia2->format('n')){
  63. $rango .= $pre . $dia1->format('j') . $conjuncion;
  64. if ($tipo != 'alternados')
  65. $rango .= self::romanizaFecha($dia2);
  66. }
  67. else {
  68. $rango .= $pre . $dia1->format('j') . ' de ' . self::romanizaMes(intval($dia1->format('n'))) . $conjuncion;
  69. if ($tipo != 'alternados')
  70. $rango .= self::romanizaFecha($dia2);
  71. }
  72. }
  73. else {
  74. $rango .= $pre . self::romanizaFecha($dia1) . $conjuncion;
  75. if ($tipo != 'alternados')
  76. $rango .= self::romanizaFecha($dia2);
  77. }
  78. return $rango;
  79. }
  80. public static function dosDigitos($num){
  81. if ($num < 10)
  82. return '0' . $num;
  83. else
  84. return $num;
  85. }
  86. }