Skip to content

Commit

Permalink
Add "I don't know anything" schedule action handler, using date param
Browse files Browse the repository at this point in the history
  • Loading branch information
iansltx committed Nov 13, 2017
1 parent 78f1f79 commit 97153ef
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion bootstrap/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@
return function(\Pimple\Container $c, $env) {
$c[DoublePass::class] = function() {
return new DoublePass(Router::buildFromClosureArray([
// no skills yet
'schedule' => function(Question $question, Answer $answer) {
date_default_timezone_set('America/New_York');
$date = $question->getParam('date', date('Y-m-d'));

$whatsHappening = "what's happening";

if ($date === date('Y-m-d')) {
$relative = 'today';
} elseif ($date === date('Y-m-d', time() - 86400)) {
$relative = 'yesterday';
} elseif ($date === date('Y-m-d', time() + 86400)) {
$relative = 'tomorrow';
} elseif (strtotime($date) > time() && strtotime($date) <= time() + 86400 * 7) {
$relative = 'on ' . date('l', strtotime($date)); // day of week
} else {
if (strtotime($date) < time()) {
$whatsHappening = 'what happened';
}
$relative = 'on the ' . date('jS', strtotime($date)); // e.g. the 13th
}

return $answer->withSpeechAndText("Sorry, but I'm not sure $whatsHappening $relative quite yet.");
}
], function(Question $question, Answer $answer) : Answer {
return $answer->withSpeechAndText("Sorry, I don't know how to help you with that.");
}));
Expand Down

0 comments on commit 97153ef

Please sign in to comment.