Skip to content

Instantly share code, notes, and snippets.

@FDSoftware
Created July 6, 2019 22:57
Show Gist options
  • Save FDSoftware/983cbe04a125786091d4408e9346b847 to your computer and use it in GitHub Desktop.
Save FDSoftware/983cbe04a125786091d4408e9346b847 to your computer and use it in GitHub Desktop.
<?php
//SRC: https://board.phpbuilder.com/d/10342598-quotconvert-quothoursminutesquot-to-quottotal-minutesquot-and-backquot/2
function hoursToMinutes($hours) {
$minutes = 0;
if (strpos($hours, ':') !== false) {
// Split hours and minutes.
list($hours, $minutes) = explode(':', $hours);
}
return $hours * 60 + $minutes;
}
function hourCompare($h1, $h2) {
$hora = preg_split("/[\s;]+/", $h1);
$hora1 = preg_split("/[\s;]+/", $h2);
$x2 = 0;
$HA = hoursToMinutes($hora1[0]);
$HB = hoursToMinutes($hora1[1]);
$H1 = hoursToMinutes($hora[0]);
$H2 = hoursToMinutes($hora[1]);
if( $H1 > $HA and $H1 < $HB ){ //primer IF, hora inicio
$x2++; // evento cruzado
}else if( $H2 >= $HA and $H2 < $HB ){ //segundo IF, hora de finalizacion
$x2++; //evento cruzado (otra ve)
}
if($x2 != 0){
return true;
}else{
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment