Source for file php_sunrise_sunset.php
Documentation is available at php_sunrise_sunset.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Alexander Wirtz <alex@pc4p.net> |
// +----------------------------------------------------------------------+
// $Id: php_sunrise_sunset.php,v 1.3 2004/07/14 11:16:05 eru Exp $
// The sun position algorithm taken from the 'US Naval Observatory's
// Almanac for Computers', implemented by Ken Bloom <kekabloom@ucdavis.edu>
// for the zmanim project <http://sourceforge.net/projects/zmanim/>
// and finally converted to C by Moshe Doron <mosdoron@netvision.net.il>.
// Taken from the PHP5 sources and converted to PHP by above authors.
if(!defined("SUNFUNCS_RET_TIMESTAMP")) {
define("SUNFUNCS_RET_TIMESTAMP", 0 );
define("SUNFUNCS_RET_STRING", 1 );
define("SUNFUNCS_RET_DOUBLE", 2 );
define("SUNFUNCS_DEFAULT_LATITUDE", 31.7667 );
define("SUNFUNCS_DEFAULT_LONGITUDE", 35.2333 );
define("SUNFUNCS_SUNRISE_ZENITH", 90.83 );
define("SUNFUNCS_SUNSET_ZENITH", 90.83 );
// step 1: First calculate the day of the year
// int N = theday - date(1, 1, theday.year()) + 1;
// step 2: convert the longitude to hour value and calculate an approximate time
$lngHour = $longitude / 15;
// use 18 for sunset instead of 6
$t = $N + ((18 - $lngHour) / 24 );
$t = $N + ((6 - $lngHour) / 24 );
// step 3: calculate the sun's mean anomaly
$M = (0.9856 * $t) - 3.289;
// step 4: calculate the sun's true longitude
assert($Lx != $L); // askingtheguru: really needed?
assert($Lx != $L); // askingtheguru: really needed?
// step 5a: calculate the sun's right ascension
assert($RAx != $RA); // askingtheguru: really needed?
assert($RAx != $RA); // askingtheguru: really needed?
// step 5b: right ascension value needs to be in the same quadrant as L
$Lquadrant = floor($L / 90 ) * 90;
$RAquadrant = floor($RA / 90 ) * 90;
$RA = $RA + ($Lquadrant - $RAquadrant);
// step 5c: right ascension value needs to be converted into hours
// step 6: calculate the sun's declination
// step 7a: calculate the sun's local hour angle
// XXX: What's the use of this block.. ?
// if (!calc_sunset && cosH > 1 || calc_sunset && cosH < -1) {
// step 7b: finish calculating H and convert into hours
// step 8: calculate local mean time
$T = $H + $RA - (0.06571 * $t) - 6.622;
// Sunset step 9: convert to UTC
assert($UTx != $UT); // askingtheguru: really needed?
assert($UTx != $UT); // askingtheguru: really needed?
function php_do_sunrise_sunset($date, $retformat, $latitude, $longitude, $zenith, $gmt_offset, $calc_sunset)
// todo: more user friendly format
// date must be timestamp for now
$N = date("z", $time) + 1;
if ($gmt_offset === "") {
$gmt_offset = date("Z", $time) / 3600;
$ret = php_sunrise_sunset($N, $latitude, $longitude, $zenith, $calc_sunset) + $gmt_offset;
return floor($time - ($time % (24 * 3600 ))) + floor(60 * $ret);
function date_sunrise($date, $retformat = "", $latitude = "", $longitude = "", $zenith = "", $gmt_offset = "")
function date_sunset($date, $retformat = "", $latitude = "", $longitude = "", $zenith = "", $gmt_offset = "")
Documentation generated on Mon, 11 Mar 2019 13:56:23 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|