forked from cbiggins/beeroclock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beeroclock.php
49 lines (40 loc) · 1.12 KB
/
beeroclock.php
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
<?php
$datefmt = 'H:i:s';
$localtimezone = 'Australia/Sydney';
$localtime = new DateTime;
$localtime->setTimeZone(new DateTimeZone($localtimezone));
$cities = array(
'London' => 'Europe/London',
'Paris' => 'Europe/Paris',
'Sydney' => 'Australia/Sydney',
'Auckland' => 'Pacific/Auckland',
'New York' => 'America/New_York',
'Los Angeles' => 'America/Los_Angeles',
'Mexico City' => 'America/Mexico_City',
'Dublin' => 'Europe/Dublin',
'Buenos Aires' => 'America/Buenos_Aires',
'Monaco' => 'Europe/Monaco',
'Rome' => 'Europe/Rome',
'Berlin' => 'Europe/Berlin',
'Helsinki' => 'Europe/Helsinki',
);
$beeroclock = array();
foreach ($cities as $city => $tz) {
$d = new DateTime;
$d->setTimeZone(new DateTimeZone($tz));
$w = $d->format('w');
$h = $d->format('H');
// What day is it?
if ($w == 6 || $w == 0) {
// Its a weekend.
$boc = 12;
}
else {
$boc = 17;
}
// Where is it beer oclock?
if ($h >= $boc) {
$beeroclock[] = array('name' => $city, 'time' => $d->format($datefmt));
}
}
print json_encode($beeroclock);