Last active
August 29, 2015 14:15
-
-
Save Insti/58ff4115c963991e0898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function insert_point( $road, $point ) | |
{ | |
// add 7 hours to the time so we're in the right timezone. | |
// you'll need to change this to match your timezone. | |
$seven_hours = 7 * 60 * 60; | |
$point[0] = $point[0] + $seven_hours; | |
// Find the right place to put it | |
$index = find_right_place( $road, $point[0] ); | |
array_splice( $road, $index, 0, array($point) ); | |
return $road; | |
} | |
function find_right_place( $road, $timestamp ) | |
{ | |
for( $i = 0; $i < sizeof( $road ) ; $i++ ) { | |
if( $road[$i][0] > $timestamp ) { | |
return $i; | |
} | |
} | |
return null; | |
} | |
function delete_point( $road, $index ) | |
{ | |
array_splice( $road, $index ); | |
return $road; | |
} | |
function pretty_road_string( $roaddata, $date_format = "Y-m-d" ) | |
{ | |
$seven_hours = 7 * 60 * 60; | |
$string = ""; | |
$i =0; | |
foreach( $roaddata as &$segment ) { | |
$segment[0]= date( $date_format, $segment[0] - $seven_hours ); | |
$string .= sprintf( "%d: [%s,%s,%s]\n", | |
$i++, | |
ornull( $segment[0]), | |
ornull( $segment[1]), | |
ornull( $segment[2]) | |
); | |
} | |
return $string; | |
} | |
function ornull( $data ) | |
{ | |
return is_null( $data ) ? 'null' : $data; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment