Subversion Repositories Sigmater

Rev

Blame | Last modification | View Log | Download | RSS feed

<?php

function mod($a,$b) {

        $x1 = (int) abs($a/$b);
        $x2 = $a/$b;
        return $a-($x1*$b);    
}    

function IsLeapYear($y) {
   
        $bulis = ((mod($y,4) == 0) && ((mod ($y,100) <> 0) || (mod($y,400) == 0)));
        return $bulis;
}

function daycount($dt) {
        
        $dc_year = (int) $dt['YY'];
        $dc_month = (int) $dt['MM'];
   
        switch ($dc_month) {

                case  1:
                case  3:
                case  5:
                case  7:
                case  8:
                case 10:
                case 12: 
                return 31;
                break;
                
                case  4:
                case  6:
                case  9:
                case 11: 
                       return 30;
                break; 

                case 2: 
                        if (IsLeapYear($dc_year))
                                return 29;
                        else
                                return 28;
                break;
        }
}


function split_sysdate() {
        
        global $sysdate;
        
        list($date, $time) = explode(' ', $sysdate);
        
        $arr_d = explode('/', $date);
        $arr_t = explode(':', $time);
        
        $arr_sysdate['DD'] = $arr_d[0];
        $arr_sysdate['MM'] = $arr_d[1];
        $arr_sysdate['YY'] = $arr_d[2];
        $arr_sysdate['HH'] = $arr_t[0];
        $arr_sysdate['MI'] = $arr_t[1];
        $arr_sysdate['SS'] = $arr_t[2];
        
        return $arr_sysdate;
}

function split_date($date) {
        
        $arr_d = explode('/', $date);
        
        $arr_date['DD'] = $arr_d[0];
        $arr_date['MM'] = $arr_d[1];
        $arr_date['YY'] = $arr_d[2];
        
        return $arr_date;
}

function sub_months($dt, $months) {
        
        $dt['MM'] = (int) $dt['MM'];
        
        if (($dt['MM'] - $months) < 1) {
                                
                $dt['MM'] = $dt['MM'] + 12;
                $dt['YY'] = $dt['YY'] - 1;
                
        }       

        $dt['MM'] = str_pad($dt['MM'] - $months, 2, '0', STR_PAD_LEFT);
        
        return $dt;
}

?>