--- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -4,27 +4,17 @@ 'saturday', 'weekday' ); -function getServiceOverride() { - global $conn; - $query = "Select * from calendar_dates where date = '".date("Ymd")."' and exception_type = '1'"; - debug($query,"database"); - $result = pg_query($conn, $query); - if (!$result) { - databaseError(pg_result_error($result)); - return Array(); - } - return pg_fetch_assoc($result); -} -function service_period() + +function service_period($date = "") { if (isset($_SESSION['service_period'])) return $_SESSION['service_period']; - $override = getServiceOverride(); + $override = getServiceOverride($date); if ($override['service_id']){ return $override['service_id']; } - switch (date('w')) { + switch (date('w',($date != "" ? $date : time()))) { case 0: return 'sunday'; case 6: @@ -33,9 +23,12 @@ return 'weekday'; } } -function midnight_seconds() +function midnight_seconds($time = "") { // from http://www.perturb.org/display/Perlfunc__Seconds_Since_Midnight.html + if ($time != "") { + return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); + } if (isset($_SESSION['time'])) { $time = strtotime($_SESSION['time']); return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time);