From 8c3333be88266a6a415d47a8a988e4ec81e99e2f Mon Sep 17 00:00:00 2001 From: Danny Gershman Date: Sat, 14 Apr 2018 00:59:47 -0400 Subject: [PATCH] implemented grace period #61 --- README.md | 4 ++++ RELEASENOTES.md | 5 +++++ fbmessenger-gateway.php | 7 ++++--- functions.php | 15 +++++++++------ meeting-search.php | 3 ++- 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 RELEASENOTES.md diff --git a/README.md b/README.md index 1e01e16c0..b90a81fdc 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ Each hint may not be more than 100 characters (including spaces). You can use u $gather_hints = ""; ``` +### Grace Period + +By default a 15 minute grace period will be applied. This can be adjust by setting `$grace_minutes` in your `config.php`. + ## Helpline Call Routing The helpline router utilizes a BMLT server (2.9.0 or later), that has helpline numbers properly configured in the "Service Body Administration" section. diff --git a/RELEASENOTES.md b/RELEASENOTES.md new file mode 100644 index 000000000..d5b849c74 --- /dev/null +++ b/RELEASENOTES.md @@ -0,0 +1,5 @@ +# Release Notes + +###1.0.1 (unreleased) + +* New feature: meeting start time grace period (default 15 minutes). https://github.com/radius314/yap/issues/61 \ No newline at end of file diff --git a/fbmessenger-gateway.php b/fbmessenger-gateway.php index a1ee4a40c..1e6fce48f 100644 --- a/fbmessenger-gateway.php +++ b/fbmessenger-gateway.php @@ -63,12 +63,13 @@ function sendMeetingResults($coordinates, $sender_id, $results_start = 0) { $settings = json_decode($client->get('messenger_user_' . $sender_id)); $today = null; $tomorrow = null; + $grace_minutes = isset($GLOBALS['grace_minutes']) ? $GLOBALS['grace_minutes'] : 15; if ($settings != null) { - if ($today == null) $today = (new DateTime($settings->set_day))->format('w') + 1; - if ($tomorrow == null) $tomorrow = (new DateTime($settings->set_day))->modify('+1 day')->format('w') + 1; + if ($today == null) $today = (new DateTime($settings->set_day))->modify(sprintf("-%s minutes", $grace_minutes) )->format('w') + 1; + if ($tomorrow == null) $tomorrow = (new DateTime($settings->set_day))->modify(sprintf("-%s minutes", $grace_minutes) )->modify('+1 day')->format('w') + 1; } - $meeting_results = getMeetings($coordinates->latitude, $coordinates->longitude, $results_count, $today, $tomorrow); + $meeting_results = getMeetings($coordinates->latitude, $coordinates->longitude, $results_count, $today, $tomorrow, $grace_minutes); } catch (Exception $e) { error_log($e); exit; diff --git a/functions.php b/functions.php index 67602e7bb..af96084ab 100644 --- a/functions.php +++ b/functions.php @@ -158,14 +158,17 @@ function getServiceBodyCoverage($latitude, $longitude) { } } -function getMeetings($latitude, $longitude, $results_count, $today = null, $tomorrow = null) -{ +function getMeetings($latitude, $longitude, $results_count, $today = null, $tomorrow = null, $grace_minutes = 15) { $time_zone_results = getTimeZoneForCoordinates($latitude, $longitude); # Could be wired up to use multiple roots in the future by using a parameter to select date_default_timezone_set($time_zone_results->timeZoneId); - if ($today == null) $today = date( "w" ) + 1; - if ($tomorrow == null) $tomorrow = (new DateTime('tomorrow'))->format("w") + 1; + if ($today == null) $today = (new DateTime()) + ->modify(sprintf("-%s minutes", $grace_minutes) ) + ->format( "w" ) + 1; + if ($tomorrow == null) $tomorrow = (new DateTime('tomorrow')) + ->modify(sprintf("-%s minutes", $grace_minutes) ) + ->format("w") + 1; $meeting_results = new MeetingResults(); $meeting_results = meetingSearch($meeting_results, $latitude, $longitude, $today); @@ -192,10 +195,10 @@ function getYapBasedHelplines() { return json_encode($yapHelplines); } -function isItPastTime($meeting_day, $meeting_time, $grace_period = 15) { +function isItPastTime($meeting_day, $meeting_time, $grace_minutes = 1) { $next_meeting_time = getNextMeetingInstance($meeting_day, $meeting_time); $time_zone_time = new DateTime(); - return $next_meeting_time <= $time_zone_time + $grace_period; + return $next_meeting_time <= $time_zone_time; } function getNextMeetingInstance($meeting_day, $meeting_time) { diff --git a/meeting-search.php b/meeting-search.php index 24f413b38..87ea33be2 100644 --- a/meeting-search.php +++ b/meeting-search.php @@ -9,7 +9,8 @@ try { $results_count = $results_count = isset($GLOBALS['result_count_max']) ? $GLOBALS['result_count_max'] : 5; - $meeting_results = getMeetings($latitude, $longitude, $results_count); + $grace_minutes = isset($GLOBALS['grace_minutes']) ? $GLOBALS['grace_minutes'] : 15; + $meeting_results = getMeetings($latitude, $longitude, $results_count, null, null, $grace_minutes); } catch (Exception $e) { header("Location: fallback.php"); exit;