Advertisement
academo

Festivos en Colombia PHP

Jun 14th, 2011
2,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.02 KB | None | 0 0
  1. <?php
  2. class Festivos
  3. {
  4.  
  5.     private $hoy;
  6.     private $festivos;
  7.     private $ano;
  8.     private $pascua_mes;
  9.     private $pascua_dia;
  10.    
  11.     public function getFestivos($ano=''){
  12.         $this->festivos($ano);
  13.         return $this->festivos;
  14.     }
  15.    
  16.     public function festivos($ano='')
  17.     {
  18.         $this->hoy=date('d/m/Y');
  19.        
  20.         if($ano=='')
  21.             $ano=date('Y');
  22.            
  23.         $this->ano=$ano;
  24.        
  25.         $this->pascua_mes=date("m", easter_date($this->ano));
  26.         $this->pascua_dia=date("d", easter_date($this->ano));
  27.                
  28.         $this->festivos[$ano][1][1]   = true;       // Primero de Enero
  29.         $this->festivos[$ano][5][1]   = true;       // Dia del Trabajo 1 de Mayo
  30.         $this->festivos[$ano][7][20]  = true;       // Independencia 20 de Julio
  31.         $this->festivos[$ano][8][7]   = true;       // Batalla de Boyacá 7 de Agosto
  32.         $this->festivos[$ano][12][8]  = true;       // Maria Inmaculada 8 diciembre (religiosa)
  33.         $this->festivos[$ano][12][25] = true;       // Navidad 25 de diciembre
  34.        
  35.         $this->calcula_emiliani(1, 6);              // Reyes Magos Enero 6
  36.         $this->calcula_emiliani(3, 19);             // San Jose Marzo 19
  37.         $this->calcula_emiliani(6, 29);             // San Pedro y San Pablo Junio 29
  38.         $this->calcula_emiliani(8, 15);             // Asunción Agosto 15
  39.         $this->calcula_emiliani(10, 12);            // Descubrimiento de América Oct 12
  40.         $this->calcula_emiliani(11, 1);             // Todos los santos Nov 1
  41.         $this->calcula_emiliani(11, 11);            // Independencia de Cartagena Nov 11
  42.        
  43.         //otras fechas calculadas a partir de la pascua.
  44.        
  45.         $this->otrasFechasCalculadas(-3);           //jueves santo
  46.         $this->otrasFechasCalculadas(-2);           //viernes santo
  47.        
  48.         $this->otrasFechasCalculadas(43,true);      //Ascención el Señor pascua
  49.         $this->otrasFechasCalculadas(64,true);      //Corpus Cristi
  50.         $this->otrasFechasCalculadas(71,true);      //Sagrado Corazón
  51.        
  52.         // otras fechas importantes que no son festivos
  53.  
  54.         // $this->otrasFechasCalculadas(-46);       // Miércoles de Ceniza
  55.         // $this->otrasFechasCalculadas(-46);       // Miércoles de Ceniza
  56.         // $this->otrasFechasCalculadas(-48);       // Lunes de Carnaval Barranquilla
  57.         // $this->otrasFechasCalculadas(-47);       // Martes de Carnaval Barranquilla
  58.     }
  59.     protected function calcula_emiliani($mes_festivo,$dia_festivo)
  60.     {
  61.         // funcion que mueve una fecha diferente a lunes al siguiente lunes en el
  62.         // calendario y se aplica a fechas que estan bajo la ley emiliani
  63.         //global  $y,$dia_festivo,$mes_festivo,$festivo;
  64.         // Extrae el dia de la semana
  65.         // 0 Domingo … 6 Sábado
  66.         $dd = date("w",mktime(0,0,0,$mes_festivo,$dia_festivo,$this->ano));
  67.         switch ($dd) {
  68.         case 0:                                    // Domingo
  69.         $dia_festivo = $dia_festivo + 1;
  70.         break;
  71.         case 2:                                    // Martes.
  72.         $dia_festivo = $dia_festivo + 6;
  73.         break;
  74.         case 3:                                    // Miércoles
  75.         $dia_festivo = $dia_festivo + 5;
  76.         break;
  77.         case 4:                                     // Jueves
  78.         $dia_festivo = $dia_festivo + 4;
  79.         break;
  80.         case 5:                                     // Viernes
  81.         $dia_festivo = $dia_festivo + 3;
  82.         break;
  83.         case 6:                                     // Sábado
  84.         $dia_festivo = $dia_festivo + 2;
  85.         break;
  86.         }
  87.         $mes = date("n", mktime(0,0,0,$mes_festivo,$dia_festivo,$this->ano))+0;
  88.         $dia = date("d", mktime(0,0,0,$mes_festivo,$dia_festivo,$this->ano))+0;
  89.         $this->festivos[$this->ano][$mes][$dia] = true;
  90.     }  
  91.     protected function otrasFechasCalculadas($cantidadDias=0,$siguienteLunes=false)
  92.     {
  93.         $mes_festivo = date("n", mktime(0,0,0,$this->pascua_mes,$this->pascua_dia+$cantidadDias,$this->ano));
  94.         $dia_festivo = date("d", mktime(0,0,0,$this->pascua_mes,$this->pascua_dia+$cantidadDias,$this->ano));
  95.        
  96.         if ($siguienteLunes)
  97.         {
  98.             $this->calcula_emiliani($mes_festivo, $dia_festivo);
  99.         }  
  100.         else
  101.         {  
  102.             $this->festivos[$this->ano][$mes_festivo+0][$dia_festivo+0] = true;
  103.         }
  104.     }  
  105.     public function esFestivo($dia,$mes)
  106.     {
  107.         //echo (int)$mes;
  108.         if($dia=='' or $mes=='')
  109.         {
  110.             return false;
  111.         }
  112.        
  113.         if (isset($this->festivos[$this->ano][(int)$mes][(int)$dia]))
  114.         {
  115.             return true;
  116.         }
  117.         else
  118.         {
  119.             return FALSE;
  120.         }
  121.    
  122.     }  
  123. }
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement