-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget-sundata
More file actions
executable file
·45 lines (39 loc) · 866 Bytes
/
get-sundata
File metadata and controls
executable file
·45 lines (39 loc) · 866 Bytes
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
#!/usr/bin/env php
<?php
// Get sunrise and sunset.
//
// Return 0, if time is between sunrise and sunset.
// Idea: https://github.com/baskerville/bin/blob/macosx/daytime
if ($argc == 2) {
$now = $argv[1];
}
if (empty($now)) {
$now = time();
}
$latitude = getenv('X_MY_LATITUDE1');
$longitude = getenv('X_MY_LONGITUDE1');
$offset = (new \DateTimeImmutable('now', new \DateTimeZone(getenv('TZ'))))
->getOffset() / 3600;
$sunrise = \date_sunrise(
$now,
\SUNFUNCS_RET_TIMESTAMP,
$latitude,
$longitude,
90.583333,
$offset
);
$sunset = \date_sunset(
$now,
\SUNFUNCS_RET_TIMESTAMP,
$latitude,
$longitude,
90.583333,
$offset
);
print strftime('%H:%M', $sunrise) . ' ' . strftime('%H:%M', $sunset) . PHP_EOL;
if ($sunrise < $now && $now < $sunset) {
exit(0);
} else {
exit(1);
}
// vim: set ft=php :