-
Notifications
You must be signed in to change notification settings - Fork 725
/
date-sun-info.xml
316 lines (307 loc) · 7.66 KB
/
date-sun-info.xml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.date-sun-info" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>date_sun_info</refname>
<refpurpose>Returns an array with information about sunset/sunrise and twilight begin/end</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>date_sun_info</methodname>
<methodparam><type>int</type><parameter>timestamp</parameter></methodparam>
<methodparam><type>float</type><parameter>latitude</parameter></methodparam>
<methodparam><type>float</type><parameter>longitude</parameter></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>timestamp</parameter></term>
<listitem>
<para>
Unix timestamp.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>latitude</parameter></term>
<listitem>
<para>
Latitude in degrees.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>longitude</parameter></term>
<listitem>
<para>
Longitude in degrees.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns an array whose structure is detailed in the following list:
</para>
<para>
<variablelist>
<varlistentry>
<term><literal>sunrise</literal></term>
<listitem>
<simpara>
The timestamp of the sunrise (zenith angle = 90°35').
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>sunset</literal></term>
<listitem>
<simpara>
The timestamp of the sunset (zenith angle = 90°35').
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>transit</literal></term>
<listitem>
<simpara>
The timestamp when the sun is at its zenith, i.e. has reached its topmost
point.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>civil_twilight_begin</literal></term>
<listitem>
<simpara>
The start of the civil dawn (zenith angle = 96°). It ends at
<literal>sunrise</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>civil_twilight_end</literal></term>
<listitem>
<simpara>
The end of the civil dusk (zenith angle = 96°). It starts at
<literal>sunset</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>nautical_twilight_begin</literal></term>
<listitem>
<simpara>
The start of the nautical dawn (zenith angle = 102°). It ends at
<literal>civil_twilight_begin</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>nautical_twilight_end</literal></term>
<listitem>
<simpara>
The end of the nautical dusk (zenith angle = 102°). It starts at
<literal>civil_twilight_end</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>astronomical_twilight_begin</literal></term>
<listitem>
<simpara>
The start of the astronomical dawn (zenith angle = 108°). It ends at
<literal>nautical_twilight_begin</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>astronomical_twilight_end</literal></term>
<listitem>
<simpara>
The end of the astronomical dusk (zenith angle = 108°). It starts at
<literal>nautical_twilight_end</literal>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The values of the array elements are either UNIX timestamps, &false; if the
sun is below the respective zenith for the whole day, or &true; if the sun is
above the respective zenith for the whole day.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>7.2.0</entry>
<entry>
The calculation was fixed with regards to local midnight instead of
local noon, which changes the results slightly.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>A <function>date_sun_info</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$sun_info = date_sun_info(strtotime("2006-12-12"), 31.7667, 35.2333);
foreach ($sun_info as $key => $val) {
echo "$key: " . date("H:i:s", $val) . "\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
sunrise: 05:52:11
sunset: 15:41:21
transit: 10:46:46
civil_twilight_begin: 05:24:08
civil_twilight_end: 16:09:24
nautical_twilight_begin: 04:52:25
nautical_twilight_end: 16:41:06
astronomical_twilight_begin: 04:21:32
astronomical_twilight_end: 17:12:00
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Polar night, with some processing</title>
<programlisting role="php">
<![CDATA[
<?php
$tz = new \DateTimeZone('America/Anchorage');
$si = date_sun_info(strtotime("2022-12-21"), 70.21, -148.51);
foreach ($si as $key => $value) {
echo
match ($value) {
true => 'always',
false => 'never',
default => date_create("@{$value}")->setTimeZone($tz)->format( 'H:i:s T' ),
},
": {$key}",
"\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
never: sunrise
never: sunset
12:52:18 AKST: transit
10:53:19 AKST: civil_twilight_begin
14:51:17 AKST: civil_twilight_end
09:01:47 AKST: nautical_twilight_begin
16:42:48 AKST: nautical_twilight_end
07:40:47 AKST: astronomical_twilight_begin
18:03:49 AKST: astronomical_twilight_end
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Midnight sun (Tromsø, Norway)</title>
<programlisting role="php">
<![CDATA[
<?php
$si = date_sun_info(strtotime("2022-06-26"), 69.68, 18.94);
print_r($si);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[sunrise] => 1
[sunset] => 1
[transit] => 1656240426
[civil_twilight_begin] => 1
[civil_twilight_end] => 1
[nautical_twilight_begin] => 1
[nautical_twilight_end] => 1
[astronomical_twilight_begin] => 1
[astronomical_twilight_end] => 1
)
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Calculating length of day (Kyiv)</title>
<programlisting role="php">
<![CDATA[
<?php
$si = date_sun_info(strtotime('2022-08-26'), 50.45, 30.52);
$diff = $si['sunset'] - $si['sunrise'];
echo "Length of day: ",
floor($diff / 3600), "h ",
floor(($diff % 3600) / 60), "s\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Length of day: 13h 56s
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->