elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  PHP - Mostrar cantidad de días del mes restando festivos en Colombia
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: PHP - Mostrar cantidad de días del mes restando festivos en Colombia  (Leído 1,463 veces)
yes id

Desconectado Desconectado

Mensajes: 1


Ver Perfil
PHP - Mostrar cantidad de días del mes restando festivos en Colombia
« en: 12 Septiembre 2018, 19:09 pm »

Buen día.

En este enlace https://pastebin.com/WQnp0s0W encontré la siguiente clase para calcular festivos:

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

Solo por si a alguien le sirve!


« Última modificación: 19 Septiembre 2018, 10:00 am por #!drvy » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines