date_sunset


php apg

RETURNS the time of SUNSET for a given day and location.


May experience difficulties in displaying characters outside of the English language when preceded with the setlocale function.


<?php

string
|int|float|false date_sunset int $timestamp 
                                                       
int $returnFormat SUNFUNCS_RET_STRING 
                                            
float|null $latitude null 
                                            
float|null $longitude null 
                                            
float|null $zenith null 
                                            
float|null $utcOffset null )


where

$timestamp The timestamp of the day from which the sunset time is taken

$returnFormat 
The constant to control the type of the result
                          
SEE the below TABLE )

$latitude The local LATITUDE
                  date
.default_latitude: as set in the php.ini

$longitude 
The local LONGITUDE
                    date
.default_longitude: as set in the php.ini

$zenith 
The angle between the center of the sun and a line 
                perpendicular to the surface of earth
               date
.sunrise_zenith: as set in the php.ini
               
SEE the below TABLE )

$utcOffset The GMT/UTC offset Specified in hours

?>

 $timestamp 


The timestamp of the day from which the sunset time is taken.



 $returnFormat 

FORMAT CONSTANTS
CONSTANT VALUE RETURNED TYPE EXAMPLE
SUNFUNCS_RET_STRING 1 STRING 14:30
SUNFUNCS_RET_DOUBLE 2 FLOAT 14.5
SUNFUNCS_RET_TIMESTAMP 0 INTEGER TIMESTAMP
ed48


 $latitude 


The local LATITUDE or date.default_latitude: as set in the php.ini.



 $longitude 


The local LONGITUDE or date.default_longitude: as set in the php.ini.



 $zenith 

COMMON zenith ANGLES
ANGLE DESCRIPTION ABOUT
90°50' The point where the sun becomes invisible SUNSET
96° Conventionally used to signify the end of dusk CIVIL TWILIGHT
102° The point at which the horizon ends being visible at sea NAUTICAL TWILIGHT
108° The point at which the sun ends being the source of any illumination ASTRONOMICAL TWILIGHT
ed48

Accommodate yourself as a privileged observer, stationed at a given point on the earth plane.

Consider tracing a vertical line, perpendicular to that plane.

The point of the celestial sphere, above his head, intercepted by this line is called ZENITH.

Z apr

SOLAR ZENITH ANGLE is the angle formed by the vertical line at the point of the earth's surface where the observer is and the line of sight passing through the Sun.

Imagine, that same vertical, extended in the opposite direction.

The point that intercepts, analogously, the celestial sphere is called NADIR.

N apr

* Illustrations from WIKIPEDIA!



 $utfOffset 


The GMT offset specified in hours.





$utfOffset is specified in hours and is ignored, if $format is SUNFUNCS_RET_TIMESTAMP.

Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable.

See also date_default_timezone_set function.

This function returns the sunset time in a specified $format on success or FALSE on failure.

One potential reason for failure is that the sun does not set at all, which happens inside the polar circles for part of the year.

The values of date.timezone, date.default_latitude, date.default_longitude and date.sunrise_zenith are defined in the php.ini configuration file and should be changed if necessary.

Otherwise, the values of $latitude, $longitude, and $zenith must be supplied to the desired location.


D apr





The section of php.ini where this can be done is shown below:



[PHP]

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = 'America/Sao_Paulo'

; http://php.net/date.default-latitude
date.default_latitude = -23.5503948

; http://php.net/date.default-longitude
date.default_longitude = -46.634513

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  1 EXERCISE   

<?php

setlocale
(LC_ALL"pt_BR.utf-8""portuguese-brazil""ptb");
date_default_timezone_set('America/Sao_Paulo');

$in_gt  ini_get('date.timezone');
$df_lat ini_get('date.default_latitude');
$df_lng ini_get('date.default_longitude');
$df_dsz ini_get('date.sunset_zenith');
// Get the values defined in php.ini

echo 'INTERNAL PARAMETERS:<br><br>';

echo 
'Latitude: ' $df_lat .'<br>Longitude: ' $df_lng '<br>Zenith: ' $df_dsz;

$tstp gettimeofday(true);

echo 
'<br><br>DATE SUNSET TYPE FORMATS:<br><br>';

echo 
'FLOAT<br>' $tstp '<br><br>';

// $sunset_def = date_sunset($tstp);
// echo 'STRING<br>' . $sunset_def . '<br><br>';

$sunset_str date_sunset($tstpSUNFUNCS_RET_STRING);
echo 
'STRING<br>' $sunset_str '<br><br>';

$sunset_dbl date_sunset($tstpSUNFUNCS_RET_DOUBLE);
echo 
'FLOAT<br>' $sunset_dbl '<br><br>';

$sunset_tm date_sunset($tstpSUNFUNCS_RET_TIMESTAMP);
echo 
'INTEGER<br>' $sunset_tm '<br><br>';

?> 

  2 EXERCISE   

<?php

setlocale
(LC_ALL"en_US""american""american english""american-english""english-american""english-us""english-usa""enu""us""usa"); 
date_default_timezone_set('America/New_York');

$tstp gettimeofday(true);

echo 
'<br>Central Park, New York, NY, USA<br><br>CURRENT TIMESTAMP:<br>' $tstp '<br><br>';

$lat 40.7828647;
$lng = -73.9675438;

$date date(DATE_W3C$tstp);

echo 
'CURRENT DATE:<br>' $date;

echo 
'<br><br>DATE SUNSET TYPE FORMATS:';

$sunset_str date_sunset($tstpSUNFUNCS_RET_STRING$lat$lng);
echo 
'<br><br>STRING<br>' $sunset_str '<br><br>';

$sunset_dbl date_sunset($tstpSUNFUNCS_RET_DOUBLE$lat$lng);
echo 
'FLOAT<br>' $sunset_dbl '<br><br>';

$sunset_tm date_sunset($tstpSUNFUNCS_RET_TIMESTAMP$lat$lng);
echo 
'INTEGER<br>' $sunset_tm;

?>

  3 EXERCISE   

<?php

//Timezones with required data for date_sunrise
$inputs = array (
//Timezone with Latitude, Longitude and GMT offset
"Pacific/Samoa" => 
array (
"Latitude" => -14.24"Longitude" => -170.72"GMT" => -11),
"US/Alaska" => 
array (
"Latitude" => 61"Longitude" => -150 "GMT" => -9),
"America/Chicago" => 
array (
"Latitude" => 41.85"Longitude" => -87.65 "GMT" => -5),
"America/Montevideo" => 
array (
"Latitude" => -34.88"Longitude" => -56.18 "GMT" => -3),
"Africa/Casablanca" => 
array (
"Latitude" => 33.65"Longitude" => "-7.58""GMT" => 0),
"Europe/Moscow" => 
array (
"Latitude" => 55.75"Longitude" => 37.58"GMT" => 4),
"Asia/Hong_Kong" => 
array (
"Latitude" => 22.28"Longitude" => 114.15 "GMT" => 8),
"Australia/Brisbane" => 
array (
"Latitude" => -27.46"Longitude" => 153.2 "GMT" => 10),
"Pacific/Wallis" => 
array (
"Latitude" => -13.3"Longitude" => -176.16"GMT" => 12),
);

foreach(
$inputs as $timezone => $value) {
echo 
"<br><br>$timezone<br>";
date_default_timezone_set($timezone);
$time mktime(8888112008);
var_dumpdate_sunset($timeSUNFUNCS_RET_STRING
$value["Latitude"], $value["Longitude"], 90$value["GMT"] ));
$time mktime(8888122008);
var_dumpdate_sunset($timeSUNFUNCS_RET_STRING
$value["Latitude"], $value["Longitude"], 90$value["GMT"]) );
}

?>