reference/datetime/functions/date-sun-info.xml
5c951013ca04161992efed8b86fb40f55669958e
...
...
@@ -84,7 +84,8 @@
84
84
<term><literal>civil_twilight_begin</literal></term>
85
85
<listitem>
86
86
<simpara>
87
-
The start of the civil dawn (zenith angle = 96°). It ends at <literal>sunrise</literal>.
87
+
The start of the civil dawn (zenith angle = 96°). It ends at
88
+
<literal>sunrise</literal>.
88
89
</simpara>
89
90
</listitem>
90
91
</varlistentry>
...
...
@@ -92,7 +93,8 @@
92
93
<term><literal>civil_twilight_end</literal></term>
93
94
<listitem>
94
95
<simpara>
95
-
The end of the civil dusk (zenith angle = 96°). It starts at <literal>sunset</literal>.
96
+
The end of the civil dusk (zenith angle = 96°). It starts at
97
+
<literal>sunset</literal>.
96
98
</simpara>
97
99
</listitem>
98
100
</varlistentry>
...
...
@@ -196,86 +198,99 @@ astronomical_twilight_end: 17:12:00
196
198
]]>
197
199
</screen>
198
200
</example>
201
+
</para>
202
+

203
+
<para>
199
204
<example>
200
-
<title>Polar night</title>
205
+
<title>Polar night, with some processing</title>
201
206
<programlisting role="php">
202
207
<![CDATA[
203
208
<?php
204
-
var_dump(date_sun_info(strtotime("2017-12-21"), 90, 0));
209
+
$tz = new \DateTimeZone('America/Anchorage');
210
+

211
+
$si = date_sun_info(strtotime("2022-12-21"), 70.21, -148.51);
212
+
foreach ($si as $key => $value) {
213
+
echo
214
+
match ($value) {
215
+
true => 'always',
216
+
false => 'never',
217
+
default => date_create("@{$value}")->setTimeZone($tz)->format( 'H:i:s T' ),
218
+
},
219
+
": {$key}",
220
+
"\n";
221
+
}
205
222
?>
206
223
]]>
207
224
</programlisting>
208
225
&example.outputs;
209
226
<screen>
210
227
<![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
-
}
228
+
never: sunrise
229
+
never: sunset
230
+
12:52:18 AKST: transit
231
+
10:53:19 AKST: civil_twilight_begin
232
+
14:51:17 AKST: civil_twilight_end
233
+
09:01:47 AKST: nautical_twilight_begin
234
+
16:42:48 AKST: nautical_twilight_end
235
+
07:40:47 AKST: astronomical_twilight_begin
236
+
18:03:49 AKST: astronomical_twilight_end
231
237
]]>
232
238
</screen>
233
239
</example>
240
+
</para>
241
+

242
+
<para>
234
243
<example>
235
-
<title>Midnight sun</title>
244
+
<title>Midnight sun (Tromsø, Norway)</title>
236
245
<programlisting role="php">
237
246
<![CDATA[
238
247
<?php
239
-
var_dump(date_sun_info(strtotime("2017-06-21"), 90, 0));
248
+
$si = date_sun_info(strtotime("2022-06-26"), 69.68, 18.94);
249
+
print_r($si);
240
250
?>
241
251
]]>
242
252
</programlisting>
243
253
&example.outputs;
244
254
<screen>
245
255
<![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
-
}
256
+
Array
257
+
(
258
+
[sunrise] => 1
259
+
[sunset] => 1
260
+
[transit] => 1656240426
261
+
[civil_twilight_begin] => 1
262
+
[civil_twilight_end] => 1
263
+
[nautical_twilight_begin] => 1
264
+
[nautical_twilight_end] => 1
265
+
[astronomical_twilight_begin] => 1
266
+
[astronomical_twilight_end] => 1
267
+
)
266
268
]]>
267
269
</screen>
268
270
</example>
269
271
</para>
270
-
</refsect1>
271
272

272
-
<refsect1 role="seealso">
273
-
&reftitle.seealso;
274
273
<para>
275
-
<simplelist>
276
-
<member><function>date_sunrise</function></member>
277
-
<member><function>date_sunset</function></member>
278
-
</simplelist>
274
+
<example>
275
+
<title>Calculating length of day (Kyiv)</title>
276
+
<programlisting role="php">
277
+
<![CDATA[
278
+
<?php
279
+
$si = date_sun_info(strtotime('2022-08-26'), 50.45, 30.52);
280
+
$diff = $si['sunset'] - $si['sunrise'];
281
+
echo "Length of day: ",
282
+
floor($diff / 3600), "h ",
283
+
floor(($diff % 3600) / 60), "s\n";
284
+
?>
285
+
]]>
286
+
</programlisting>
287
+
&example.outputs;
288
+
<screen>
289
+
<![CDATA[
290
+
Length of day: 13h 56s
291
+
]]>
292
+
</screen>
293
+
</example>
279
294
</para>
280
295
</refsect1>
281
296

282
297