Skip to content

Commit

Permalink
implemented grace period #61
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Gershman committed Apr 14, 2018
1 parent 6713456 commit 8c3333b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions fbmessenger-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion meeting-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8c3333b

Please sign in to comment.