This repository was archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
50 lines (50 loc) · 1.52 KB
/
functions.php
File metadata and controls
50 lines (50 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
function calculateNextCoffeeTweet($now = false){
if(!$now) $now = time();
$timearea = false;
$nextcoffeetweet = false;
$beforework = mktime(9,30);
$beforelunch = mktime(11,15);
$afterlunch = mktime(14,00);
$evening = mktime(17,30);
if($now < $beforework){
$timearea = 'beforework';
} elseif($now < $beforelunch){
$timearea = 'am';
} elseif($now < $afterlunch){
$timearea = 'lunch';
} elseif($now < $evening){
$timearea = 'pm';
} else {
$timearea = 'evening';
}
switch($timearea){
case 'beforework':
$nextcoffeetweet = mktime(9,30);
break;
case 'am':
$nextcoffeetweet = $now + ((60 + (rand(0,20)-10)) * 60);
if($nextcoffeetweet > $beforelunch){
$nextcoffeetweet = $afterlunch + rand(0,20) * 60;
}
break;
case 'lunch':
$nextcoffeetweet = $now + ((60 + (rand(0,20)-10)) * 60);
if($nextcoffeetweet < $afterlunch){
$nextcoffeetweet = $afterlunch + rand(0,20) * 60;
}
break;
case 'pm';
$nextcoffeetweet = $now + ((90 + (rand(0,40)-20)) * 60);
if($nextcoffeetweet > $evening){
$nextcoffeetweet = (mktime(9,30,00,date("n",time()+86400),date("j",time()+86400),date("Y",time()+86400)))+ (rand(0,20)-10) * 60;
}
break;
default:
$nextcoffeetweet = (mktime(9,30,00,date("n",time()+86400),date("j",time()+86400),date("Y",time()+86400)))+ (rand(0,20)-10) * 60;
break;
}
if(date("w",$nextcoffeetweet) == "0") $nextcoffeetweet = $nextcoffeetweet + 86400;
if(date("w",$nextcoffeetweet) == "6") $nextcoffeetweet = $nextcoffeetweet + 172800;
return $nextcoffeetweet;
}