reference/datetime/functions/date-sun-info.xml
03b6583a4ade7a2b68b57fe958d2d9022b15a873
03b6583a4ade7a2b68b57fe958d2d9022b15a873
...
...
@@ -50,8 +50,7 @@
50
50
<refsect1 role="returnvalues">
51
51
&reftitle.returnvalues;
52
52
<para>
53
-
Returns array on success&return.falseforfailure;.
54
-
The structure of the array is detailed in the following list:
53
+
Returns an array whose structure is detailed in the following list:
55
54
</para>
56
55
<para>
57
56
<variablelist>
...
...
@@ -84,7 +83,8 @@
84
83
<term><literal>civil_twilight_begin</literal></term>
85
84
<listitem>
86
85
<simpara>
87
-
The start of the civil dawn (zenith angle = 96°). It ends at <literal>sunrise</literal>.
86
+
The start of the civil dawn (zenith angle = 96°). It ends at
87
+
<literal>sunrise</literal>.
88
88
</simpara>
89
89
</listitem>
90
90
</varlistentry>
...
...
@@ -92,7 +92,8 @@
92
92
<term><literal>civil_twilight_end</literal></term>
93
93
<listitem>
94
94
<simpara>
95
-
The end of the civil dusk (zenith angle = 96°). It starts at <literal>sunset</literal>.
95
+
The end of the civil dusk (zenith angle = 96°). It starts at
96
+
<literal>sunset</literal>.
96
97
</simpara>
97
98
</listitem>
98
99
</varlistentry>
...
...
@@ -196,86 +197,99 @@ astronomical_twilight_end: 17:12:00
196
197
]]>
197
198
</screen>
198
199
</example>
200
+
</para>
201
+
202
+
<para>
199
203
<example>
200
-
<title>Polar night</title>
204
+
<title>Polar night, with some processing</title>
201
205
<programlisting role="php">
202
206
<![CDATA[
203
207
<?php
204
-
var_dump(date_sun_info(strtotime("2017-12-21"), 90, 0));
208
+
$tz = new \DateTimeZone('America/Anchorage');
209
+
210
+
$si = date_sun_info(strtotime("2022-12-21"), 70.21, -148.51);
211
+
foreach ($si as $key => $value) {
212
+
echo
213
+
match ($value) {
214
+
true => 'always',
215
+
false => 'never',
216
+
default => date_create("@{$value}")->setTimeZone($tz)->format( 'H:i:s T' ),
217
+
},
218
+
": {$key}",
219
+
"\n";
220
+
}
205
221
?>
206
222
]]>
207
223
</programlisting>
208
224
&example.outputs;
209
225
<screen>
210
226
<![CDATA[
211
-
array(9) {
212
-
["sunrise"]=>
213
-
bool(false)
214
-
["sunset"]=>
215
-
bool(false)
216
-
["transit"]=>
217
-
int(1513857490)
218
-
["civil_twilight_begin"]=>
219
-
bool(false)
220
-
["civil_twilight_end"]=>
221
-
bool(false)
222
-
["nautical_twilight_begin"]=>
223
-
bool(false)
224
-
["nautical_twilight_end"]=>
225
-
bool(false)
226
-
["astronomical_twilight_begin"]=>
227
-
bool(false)
228
-
["astronomical_twilight_end"]=>
229
-
bool(false)
230
-
}
227
+
never: sunrise
228
+
never: sunset
229
+
12:52:18 AKST: transit
230
+
10:53:19 AKST: civil_twilight_begin
231
+
14:51:17 AKST: civil_twilight_end
232
+
09:01:47 AKST: nautical_twilight_begin
233
+
16:42:48 AKST: nautical_twilight_end
234
+
07:40:47 AKST: astronomical_twilight_begin
235
+
18:03:49 AKST: astronomical_twilight_end
231
236
]]>
232
237
</screen>
233
238
</example>
239
+
</para>
240
+
241
+
<para>
234
242
<example>
235
-
<title>Midnight sun</title>
243
+
<title>Midnight sun (Tromsø, Norway)</title>
236
244
<programlisting role="php">
237
245
<![CDATA[
238
246
<?php
239
-
var_dump(date_sun_info(strtotime("2017-06-21"), 90, 0));
247
+
$si = date_sun_info(strtotime("2022-06-26"), 69.68, 18.94);
248
+
print_r($si);
240
249
?>
241
250
]]>
242
251
</programlisting>
243
252
&example.outputs;
244
253
<screen>
245
254
<![CDATA[
246
-
array(9) {
247
-
["sunrise"]=>
248
-
bool(true)
249
-
["sunset"]=>
250
-
bool(true)
251
-
["transit"]=>
252
-
int(1498046510)
253
-
["civil_twilight_begin"]=>
254
-
bool(true)
255
-
["civil_twilight_end"]=>
256
-
bool(true)
257
-
["nautical_twilight_begin"]=>
258
-
bool(true)
259
-
["nautical_twilight_end"]=>
260
-
bool(true)
261
-
["astronomical_twilight_begin"]=>
262
-
bool(true)
263
-
["astronomical_twilight_end"]=>
264
-
bool(true)
265
-
}
255
+
Array
256
+
(
257
+
[sunrise] => 1
258
+
[sunset] => 1
259
+
[transit] => 1656240426
260
+
[civil_twilight_begin] => 1
261
+
[civil_twilight_end] => 1
262
+
[nautical_twilight_begin] => 1
263
+
[nautical_twilight_end] => 1
264
+
[astronomical_twilight_begin] => 1
265
+
[astronomical_twilight_end] => 1
266
+
)
266
267
]]>
267
268
</screen>
268
269
</example>
269
270
</para>
270
-
</refsect1>
271
271
272
-
<refsect1 role="seealso">
273
-
&reftitle.seealso;
274
272
<para>
275
-
<simplelist>
276
-
<member><function>date_sunrise</function></member>
277
-
<member><function>date_sunset</function></member>
278
-
</simplelist>
273
+
<example>
274
+
<title>Calculating length of day (Kyiv)</title>
275
+
<programlisting role="php">
276
+
<![CDATA[
277
+
<?php
278
+
$si = date_sun_info(strtotime('2022-08-26'), 50.45, 30.52);
279
+
$diff = $si['sunset'] - $si['sunrise'];
280
+
echo "Length of day: ",
281
+
floor($diff / 3600), "h ",
282
+
floor(($diff % 3600) / 60), "s\n";
283
+
?>
284
+
]]>
285
+
</programlisting>
286
+
&example.outputs;
287
+
<screen>
288
+
<![CDATA[
289
+
Length of day: 13h 56s
290
+
]]>
291
+
</screen>
292
+
</example>
279
293
</para>
280
294
</refsect1>
281
295
282
296