php-doc-en/reference/datetime/functions/date-sun-info.xml
2018-02-13 13:44:31 +00:00

301 lines
7.2 KiB
XML

<?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>time</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>time</parameter></term>
<listitem>
<para>
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 array on success&return.falseforfailure;.
The structure of the array is detailed in the following list:
</para>
<para>
<variablelist>
<varlistentry>
<term><literal>sunrise</literal></term>
<listitem>
<simpara>
The time of the sunrise (zenith angle = 90°35').
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>sunset</literal></term>
<listitem>
<simpara>
The time of the sunset (zenith angle = 90°35').
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>transit</literal></term>
<listitem>
<simpara>
The time 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;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.2.2</entry>
<entry>
The order of <parameter>latitude</parameter> and
<parameter>longitude</parameter> has been swapped.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</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>
<example>
<title>Polar night</title>
<programlisting role="php">
<![CDATA[
<?php
var_dump(date_sun_info(strtotime("2017-12-21"), 90, 0));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(9) {
["sunrise"]=>
bool(false)
["sunset"]=>
bool(false)
["transit"]=>
int(1513857490)
["civil_twilight_begin"]=>
bool(false)
["civil_twilight_end"]=>
bool(false)
["nautical_twilight_begin"]=>
bool(false)
["nautical_twilight_end"]=>
bool(false)
["astronomical_twilight_begin"]=>
bool(false)
["astronomical_twilight_end"]=>
bool(false)
}
]]>
</screen>
</example>
<example>
<title>Midnight sun</title>
<programlisting role="php">
<![CDATA[
<?php
var_dump(date_sun_info(strtotime("2017-06-21"), 90, 0));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(9) {
["sunrise"]=>
bool(true)
["sunset"]=>
bool(true)
["transit"]=>
int(1498046510)
["civil_twilight_begin"]=>
bool(true)
["civil_twilight_end"]=>
bool(true)
["nautical_twilight_begin"]=>
bool(true)
["nautical_twilight_end"]=>
bool(true)
["astronomical_twilight_begin"]=>
bool(true)
["astronomical_twilight_end"]=>
bool(true)
}
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>date_sunrise</function></member>
<member><function>date_sunset</function></member>
</simplelist>
</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
-->