-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeslots.php
More file actions
62 lines (51 loc) · 1.68 KB
/
Timeslots.php
File metadata and controls
62 lines (51 loc) · 1.68 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
51
52
53
54
55
56
57
58
59
60
61
62
<?php
date_default_timezone_set('America/Los_Angeles');
class Timeslots
{
public $timeSlots;
final public static function readTimeslots()
{
$jsonFile = 'timeslot.json';
$jsonStr = file_get_contents($jsonFile);
return json_decode($jsonStr, true);
}
public function getTimeslots()
{
return $this->timeSlots;
}
// Returns the details of the current time slot
final public static function checkCurrentMeetingGivenSlots($timeSlots, $beforeTime=1, $afterTime=1)
{
$currentDay = date('l'); // Current day of the week
$currentTime = date('H:i'); // Current time
foreach ($timeSlots as $day => $slots) {
foreach ($slots as $time => $details) {
if ($day === $currentDay) {
list($startTime, $endTime) = explode('-', $time);
$startTime = date('H:i', strtotime($startTime . ' -'.$beforeTime.' minutes'));
$endTime = date('H:i', strtotime($endTime . ' +'.$afterTime.' minutes'));
if ($currentTime >= $startTime && $currentTime <= $endTime) {
return $details;
}
}
}
}
return false;
}
public function checkCurrentMeeting($beforeTime=1, $afterTime=1)
{
return self::checkCurrentMeetingGivenSlots($this->timeSlots, $beforeTime, $afterTime);
}
public function __construct()
{
$this->timeSlots = self::readTimeslots();
}
public function __destruct()
{
$this->timeSlots = null;
}
public function __toString()
{
return json_encode($this->timeSlots);
}
}