|
<?php |
|
|
|
date_default_timezone_set('America/New_York'); |
|
|
|
$host = 'http://mannservices.mannlib.cornell.edu/LibServices'; |
|
$now = time(); |
|
// uncomment $now for testing system with different datetime |
|
// $now = strtotime('Sep. 13, 2012 8am'); |
|
$timeFormat = 'g:i a'; |
|
$timeAmPm = 'a'; |
|
$timeCompareFormat = 'Gi'; |
|
$dateCompareFormat = 'Ymd'; |
|
|
|
function getJson($url) { |
|
// grab the contents of the service call and decode the json object |
|
$curl_handle=curl_init(); |
|
curl_setopt($curl_handle, CURLOPT_URL, $url); |
|
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); |
|
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); |
|
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 2); |
|
$data = curl_exec($curl_handle); |
|
curl_close($curl_handle); |
|
$c = json_decode($data); |
|
return $c; |
|
} |
|
|
|
function getHours($date, $location) { |
|
global $host; |
|
$formattedDate = date('Y-m-d', $date); |
|
$url = $host . '/showLibraryHoursForDate.do?location=' . $location . '&date=' . $formattedDate . '&output=json'; |
|
|
|
$todaysHours = getJson($url); |
|
|
|
return $todaysHours; |
|
} |
|
|
|
function openingTime($location) { |
|
global $now, $timeCompareFormat; |
|
$todaysHours = getHours($now, $location); |
|
|
|
$openingTime = $todaysHours->startTime; |
|
|
|
return $openingTime; |
|
} |
|
|
|
function openNow($location) { |
|
global $now, $timeCompareFormat; |
|
$todaysHours = getHours($now, $location); |
|
|
|
$startTimeCompare = date($timeCompareFormat, $todaysHours->startTime); |
|
$endTimeCompare = date($timeCompareFormat, $todaysHours->endTime); |
|
$overrideFlag = $todaysHours->override; |
|
|
|
// Check if closed all day or open but already passed closing time |
|
if ($overrideFlag == 2 || ($endTimeCompare < date($timeCompareFormat, $now)) { |
|
return false; |
|
} |
|
else { |
|
return true; |
|
} |
|
} |
|
|
|
function stillOpenFromYesterday($location) { |
|
global $now, $timeCompareFormat; |
|
$yesterdaysHours = getHours(strtotime('yesterday', $now), $location); |
|
$yesterdayClose = $yesterdaysHours->endTime; |
|
$yesterdayCloseCompare = date($timeCompareFormat, $yesterdayClose); |
|
|
|
if ($yesterdayCloseCompare < 600 && date($timeCompareFormat, $now) < $yesterdayCloseCompare) { |
|
return $yesterdayClose; |
|
} |
|
else { |
|
return false; |
|
} |
|
} |
|
|
|
function closedToday($location) { |
|
global $now, $timeCompareFormat; |
|
$todaysHours = getHours($now, $location); |
|
|
|
$overrideFlag = $todaysHours->override; |
|
|
|
if ($overrideFlag == 2) { |
|
return true; |
|
} |
|
else { |
|
return false; |
|
} |
|
} |
|
|
|
function closingTime($location) { |
|
global $now, $timeCompareFormat; |
|
$todaysHours = getHours($now, $location); |
|
|
|
$stillOpenFromYesterday = stillOpenFromYesterday($location); |
|
if (!$stillOpenFromYesterday) { |
|
$closingTime = $todaysHours->endTime; |
|
} |
|
else { |
|
$closingTime = $stillOpenFromYesterday; |
|
} |
|
|
|
return $closingTime; |
|
} |
|
|
|
?> |