// PHP database connection
// Set DB parameters - (no user required on localhost)
$dbhost = 'localhost';
$dbuser = 'worldfli_wfuser';
$dbpass = 'fullM0tion';
$db = 'worldfli_worldflight';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
if(! $conn )
{
die('Could not connect: ' . mysqli_error($db));
}
?>
//define internal function for this routine
function dateconvert($datein, $offset)
{
// Year Format is yyyy-mm-dd
$dateday=substr($datein,8,2);
$datemonth=substr($datein,5,2);
$dateyear=substr($datein,0,4);
$dayout=$dateday + $offset;
if ($dayout =="00")
{
$dayout="31";
$datemonth=$datemonth -1;
}
if(strlen($dayout)==1) {$dayout = "0".$dayout ; }
$dateout= $dayout."/".$datemonth."/".$dateyear;
return ($dateout);
}
?>
// this function changes date strings and is called from timeconvert function
// this function converts time and date into UTC and local as required
// by passing the details and an appropriate offset;
// Offset must include +11 for Sydney as all times were entered as local.
function timeconvert($thetime, $thedate, $offset)
{
//this section parses the time dependant 00:00:00
$thehours=substr($thetime,0,2);
$themins=substr($thetime,3,2);
if(strlen($offset)==5) //allow for signs - i.e. -1000
{
$offhours=substr($offset,1,2);
$offmins=substr($offset,3,2);
}
elseif(strlen($offset)==4) //ie covers 1000
{
$offhours=substr($offset,0,2);
$offmins=substr($offset,2,2);
}
else
{
$offhours=substr($offset,0,1);
$offmins=substr($offset,1,2);
}
//in converting the time, if the start of the string is a -ve, we must add
if ($offmins >= 60)
{
$offmins=$offmins - 40;
}
if(substr($offset,0,1)=="-")
{
$outhours=$thehours + $offhours;
$outmins=$themins + $offmins;
}
else
{
$outhours=$thehours - $offhours;
$outmins=$themins - $offmins;
}
//check minutes and modify hours and mins as required
if($outmins < 0) // must dectrement hours
if(substr($outmins,0,1)=="-")
{
$outhours=$outhours - 1;
$outmins=$outmins + 60;
}
elseif ($outmins >= 60)
{
$outhours=$outhours + 1;
$outmins=$outmins - 60;
}
//ensure '00' is reported instead of vblank
if ($outmins=="") { $outmins="00"; }
if (strlen($outmins)==1) { $outmins="0".$outmins ; }
//check hours and modify date as required
if($outhours < 0) // must dectrement days
{
$outhours=$outhours + 24;
$outdate = dateconvert($thedate, "-1");
}
elseif ($outhours >= 24)
{
$outhours=$outhours - 24;
$outdate = dateconvert($thedate, "1");
}
else
{
// $outdate=$thedate;
$outdate = dateconvert($thedate, "0");
}
if ($outhours=="") { $outhours="00"; }
if (strlen($outhours)==1) { $outhours="0".$outhours ; }
$outtime=$outhours.":".$outmins;
//cant return multiple values (date and time) so return an array that holds these instead.
return array ($outtime, $outdate);
}
?>