<?php
  $arrMinggu[1] = "ISNIN";
  $arrMinggu[2] = "SELASA";
  $arrMinggu[3] = "RABU";
  $arrMinggu[4] = "KHAMIS";
  $arrMinggu[5] = "JUMAAT";
  $arrMinggu[6] = "SABTU";
  $arrMinggu[7] = "AHAD";

  $arrWeek[1] = "MONDAY";
  $arrWeek[2] = "TUESDAY";
  $arrWeek[3] = "WEDNESDAY";
  $arrWeek[4] = "THURSDAY";
  $arrWeek[5] = "FRIDAY";
  $arrWeek[6] = "SATURDAY";
  $arrWeek[7] = "SUNDAY";

  $arrMonth[1] = "JAN";
  $arrMonth[2] = "FEB";
  $arrMonth[3] = "MAC";
  $arrMonth[4] = "APR";
  $arrMonth[5] = "MAY";
  $arrMonth[6] = "JUN";
  $arrMonth[7] = "JUL";
  $arrMonth[8] = "AUG";
  $arrMonth[9] = "SEP";
  $arrMonth[10] = "OCT";
  $arrMonth[11] = "NOV";
  $arrMonth[12] = "DEC";
  
  $arrYear[0] = date("Y")-2;
  $arrYear[1] = date("Y")-1;
  $arrYear[2] = date("Y");
  $arrYear[3] = date("Y")+1;

?>
<?php
  function getDateBtw($date1,$date2){

    //--- reverse date
    if($date1>$date2){
	  $temp = $date1;
	  $date1 = $date2;
	  $date2 = $temp;
	}

    if($date1!=$date2){

	  $mkdate2 = getMKDate($date2);
	  
      $i=0;
	  while($date1<=$date2){

		$arrDate[$i] = $date1;
        $mkdate1 = getMKDate($date1) + 86400;
        $date1 = getRlDate($mkdate1);

        $i++;
	  }

	}else{
	  $arrDate[0]=$date1;
	}
	
	return $arrDate;
	
  }
?>
<?php
  function getWeek($date){
    $mkdate = getMKDate($date);
	$output = date("D",$mkdate);
	return $output;
  }
?>
<?php
  function getWeek2($date){
    $mkdate = getMKDate($date);
	$output = date("w",$mkdate);
	return $output;
  }
?>
<?php
  function getMKDate($date){
    $arrDate = explode("-",$date);
	$output = mktime("0","0","0",$arrDate[1],$arrDate[2],$arrDate[0]);
	return $output;
  }
?>
<?php
  function getRlDate($mkdate){
    return date("Y-m-d",$mkdate);
  }
?>
<?php
  function getArrDate($pdate,$c){
    $mymktime = getMKDate($pdate);
	$output[] = $pdate;
	for($i=1;$i<$c;$i++){
	  $mymktime = $mymktime + 86400;
	  $output[] = getRlDate($mymktime);
	}
	return $output;
  }
?>
<?php
  function chkPubHol($date){
    global $conn;
    $query = "SELECT * FROM ".$CLIENTID."_attendace_holiday 
               WHERE holDateFm <= '$date' AND holDateTo >= '$date'";
    $result = mysqli_query($conn,$query);
    $num = mysqli_num_rows($result);
	if($myrow = mysqli_fetch_array($result)){
	  $output = $myrow["holDesc"];
	}else{
	  $output = "";
	}
	return $output;
  }
?>
<?php
  function get2pc($value){
    if( strlen($value)<2 ){
	  $output = "0" . $value;
	}else{
	  $output = $value;
	}
	return $output;
  }
?>
<?php
  function addTime($otime,$atime){
    $arrOtime = explode(":",$otime);
	$arrAtime = explode(":",$atime);

    $sec = $arrOtime[2]+$arrAtime[2];
	$min = $arrOtime[1]+$arrAtime[1];
	$hr = $arrOtime[0]+$arrAtime[0];

    if( $sec>59 ){
	  $tmin = floor($sec/60);
	  $tsec = $sec%60;
	  $sec = $tsec;
	  $min = $min+$tmin;
	}
	
    if( $min>59 ){
	  $thr = floor($min/60);
	  $tmin = $min%60;
	  $min = $tmin;
	  $hr = $hr+$thr;
	}

    $sec = get2pc($sec);
    $min = get2pc($min);
    $hr = get2pc($hr);

    return "$hr:$min:$sec";

  }
?>
<?php
//  getDifSec("18:21:00","2009-06-05",$mynowtime,$mynowdate);
  
  function getDifSec($tfr,$dfr,$tto,$dto){

    $arrTimeF = explode(":",$tfr);
    $arrTimeT = explode(":",$tto);
    $arrDateF = explode("-",$dfr);
    $arrDateT = explode("-",$dto);
	
    $mytime1 = mktime( $arrTimeF[0] , $arrTimeF[1] , $arrTimeF[2] , $arrDateF[1] , $arrDateF[2] , $arrDateF[0] );

//	return round( ( (time()-$mytime1)/60 ),2 );
    return (time()-$mytime1);

//	echo time() . "<br>" . $mytime1 . "<br>";
//	echo $arrDateF[1] ."<br>". $arrDateF[2] ."<br>". $arrDateF[0];
  }

  function getDifSec2($tfr,$dfr,$tto,$dto){
//    echo "$tfr,$dfr,$tto,$dto<br>";
//    echo "[$tfr] |$tto| ---- ";

    $arrTimeF = explode(":",$tfr);
    $arrTimeT = explode(":",$tto);
    $arrDateF = explode("-",$dfr);
    $arrDateT = explode("-",$dto);
	
    $mytime1 = mktime( $arrTimeF[0] , $arrTimeF[1] , $arrTimeF[2] , $arrDateF[1] , $arrDateF[2] , $arrDateF[0] );
//	echo "[".$mytime1.",".date("Y-m-d h:i:s",$mytime1)."]<br>";
	$mytime2 = mktime( $arrTimeT[0] , $arrTimeT[1] , $arrTimeT[2] , $arrDateT[1] , $arrDateT[2] , $arrDateT[0] );
//	echo "[".$mytime2.",".date("Y-m-d h:i:s",$mytime2)."]<br>";

//	return round( ( (time()-$mytime1)/60 ),2 );
//    echo $mytime2 . " - " . $mytime1 . " = " . ($mytime2-$mytime1) . "<br>";
    return ($mytime2-$mytime1);

//	echo time() . "<br>" . $mytime1 . "<br>";
//	echo $arrDateF[1] ."<br>". $arrDateF[2] ."<br>". $arrDateF[0];
  }

  
  function conv2pc($value){
    if( strlen($value)<2 ){
	  $output = "0" . $value;
	}else{
	  $output = $value;
	}
	return $output;
  }
  
  function secConvTime($sec){
    $sec = sqrt(pow($sec,2));
	$tsecmin = ($sec%3600);
	
    $mysec = conv2pc( ($sec%60) );
	$mymin = conv2pc( floor($tsecmin/60) );
	$myhr = conv2pc( floor($sec/3600) );

	return "$myhr:$mymin:$mysec";
  }
?>