-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwilight.php
executable file
·63 lines (54 loc) · 2.06 KB
/
twilight.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
// Copyright © 2012 onwards, Nicolas Martignoni <[email protected]>
//
// License: This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
*/
/*
// This script computes the begin and end civil twilight time
// Usage: php twilight.php or
// Usage: php twilight.php --lat=<latitude> --long=<longitude> --timestamp=<unixtimestamp>
// Output: begin and end civil twilight time in 24-hour format,
// separated with a space, e.g. 2146 0530
*/
// Default values
// Localisation: Épendes
$lat = 46.762333; // North
$long = 7.139444; // East
// Set timezone if not defined
$ini_tz = ini_get('date.timezone');
if (empty($ini_tz)) {
date_default_timezone_set('Europe/Zurich');
}
// Current time
$timestamp = time();
$opts= array("timestamp::", "long::", "lat::");
$options = getopt("",$opts);
// Override default values if parameters are given
foreach( $options as $key => $value ) {
${$key} = $value;
}
if ( date('I', $timestamp) ) { // difference between GMT and local time in hours
$offset = 2;
} else {
$offset = 1;
}
$zenith=96; // Sun zenith angle at twilight begin/end, i.e. 6 degrees under horizon
$yesterday_twilightend = date_sunset($timestamp - 60 * 60 * 24, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset);
$today_twilightbegin = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith, $offset);
if ( PHP_SAPI === 'cli' ) {
echo date("Hi", $yesterday_twilightend);
echo " ";
echo date("Hi", $today_twilightbegin);
echo "\n";
} else {
echo "<p>\"Civilian Twilight\" yesterday end: ".date("Hi", $yesterday_twilightend);
echo "<br>\"Civilian Twilight\" today start: ".date("Hi", $today_twilightbegin);
}
?>