コード例 #1
0
ファイル: handler.php プロジェクト: Alambos/bot
 function data($msg, $params)
 {
     $arg = funcs::utfToAscii($msg->args);
     if (empty($arg)) {
         $data = time();
     } else {
         $data = calendar::parse_date($arg);
         if (!$data) {
             return new BotMsg('Podana data nie została rozpoznana<br />' . "\n" . '<br />' . "\n" . '<u>Przykłady:</u><br />' . "\n" . 'data<br />' . "\n" . 'data pojutrze<br />' . "\n" . 'data 1.01.2009');
         }
     }
     if (date('d.m.Y') == date('d.m.Y', $data)) {
         $txt = 'Dziś jest ';
     } else {
         $txt = 'Wybrany dzień to ';
     }
     include './data/data/data.php';
     $txt .= self::$dni[date('w', $data)] . ', ' . date('j', $data) . ' ' . self::$miesiace[date('n', $data)] . ' ' . date('Y', $data) . ' r., ' . (date('z', $data) + 1) . ' dzień roku.<br />' . "\n" . '<br />' . "\n";
     $msg->session->setClass('pogoda');
     if (!isset($msg->session->geo)) {
         $geo = array('lon' => '52.25', 'lat' => '21.0');
     } else {
         $geo = $msg->session->geo;
     }
     $txt .= 'Imieniny: ' . $imieniny[date('n', $data)][date('j', $data)] . '<br />' . "\n" . 'Wschód Słońca: ' . date_sunrise($data, SUNFUNCS_RET_STRING, $geo['lat'], $geo['lon'], 90.58, 1 + date('I')) . '<br />' . "\n" . 'Zachód Słońca: ' . date_sunset($data, SUNFUNCS_RET_STRING, $geo['lat'], $geo['lon'], 90.58, 1 + date('I'));
     return new BotMsg($txt);
 }
コード例 #2
0
function hora()
{
    echo "Amanecer: ";
    echo date_sunrise(time()) . "<br>";
    echo "Atardecer: ";
    echo date_sunset(time());
}
コード例 #3
0
ファイル: Time.php プロジェクト: buzzboard/buzzboard-php-sdk
 /**
  * Returns sunrise time
  * @param float $latitude
  * @param float $longitude
  * @param null|int $timestamp If not set, current timestamp will be used.
  * @param null|int $gmtOffset If not set, current GMT offset will be used.
  * @static
  * @return string
  */
 public static function getSunriseTime($latitude, $longitude, $timestamp = null, $gmtOffset = null)
 {
     $timestamp = self::checkTimestamp($timestamp);
     if (!$gmtOffset) {
         $gmtOffset = self::getGmtOffset();
     }
     return date_sunrise($timestamp, SUNFUNCS_RET_STRING, $latitude, $longitude, ini_get('date.sunrise_zenith'), $gmtOffset);
 }
コード例 #4
0
ファイル: h2ha.php プロジェクト: bangnaga/HomeOverlord
function getSunrise($m = true)
{
    $d = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $GLOBALS['config']['geo']['lat'], $GLOBALS['config']['geo']['long'], $GLOBALS['config']['geo']['zenith'], timeZoneOffset());
    if ($m) {
        $d = dateToMinutes($d);
    }
    return $d;
}
コード例 #5
0
 /**
  * @Route("/vychod-a-zapad-slunce/{when}", name="sunrise_and_sunset", defaults={"when"="0"}, requirements={"when"="\d+"})
  * @Template()
  */
 public function sunriseAndSunsetAction($when)
 {
     $date = new \DateTime();
     $date->add(new \DateInterval("P" . $when . "D"));
     date_default_timezone_set("Europe/Prague");
     $sunrise = date_sunrise($date->getTimestamp(), SUNFUNCS_RET_STRING, 50.0872, 14.4211);
     $sunset = date_sunset($date->getTimestamp(), SUNFUNCS_RET_STRING, 50.0872, 14.4211);
     return ['sunrise' => $sunrise, 'sunset' => $sunset, 'date' => $date];
 }
コード例 #6
0
ファイル: Weather.php プロジェクト: squaredcircle/GroupBot
 /**
  * @param float $latitude
  * @param float $longitude
  * @param int $zenith
  * @param int $gmt
  * @return Sunrise
  * Defaults to Perth, Western Australia
  */
 public static function sunrise($selection = 'perth', $zenith = 90 + 50 / 60)
 {
     $latitude = self::$coordinates[$selection][0];
     $longitude = self::$coordinates[$selection][1];
     $gmt = self::$coordinates[$selection][2];
     $sunrise = date_sunrise(time(), SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith, $gmt);
     $sunset = date_sunset(time(), SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith, $gmt);
     return new Sunrise($latitude, $longitude, $zenith, $gmt, "Perth", $sunrise, $sunset);
 }
コード例 #7
0
ファイル: NightDetector.php プロジェクト: rob-st/Runalyze
 /**
  * @param int $timestamp
  * @param \League\Geotools\Coordinate\CoordinateInterface $coordinate
  * @param int $offset
  * @return \Runalyze\Calculation\NightDetector $this-reference
  * @throws \InvalidArgumentException
  */
 public function setFrom($timestamp, CoordinateInterface $coordinate, $offset = 0)
 {
     if (!is_numeric($timestamp)) {
         throw new \InvalidArgumentException('Provided timestamp must be numerical.');
     }
     $isAfterSunset = $timestamp > date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, $coordinate->getLatitude(), $coordinate->getLongitude(), self::ZENITH, $offset);
     $isBeforeSunrise = $timestamp < date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, $coordinate->getLatitude(), $coordinate->getLongitude(), self::ZENITH, $offset);
     $this->Value = $isAfterSunset || $isBeforeSunrise;
     return $this;
 }
コード例 #8
0
ファイル: analysis.php プロジェクト: bec-uk/bec_fault_mon
/**
 * Function to highlight when a generation meter has power readings of zero
 * over the last day despite decent sol_rad figures (>DECENT_SOLRAD_LIMIT W/m2).
 * It looks at each half-hourly measurement.
 *
 * @param resource $becDB
 * @return boolean TRUE if any unexpected zero generation periods seen
 */
function zeroPowerYesterday(&$becDB)
{
    global $verbose, $graphsEnabled;
    // TODO: Tune this value to remove false hits; we wouldn't expect any power
    // output when it's really dim...
    define('DECENT_SOLRAD_LIMIT', 30);
    $dateTime = getYesterdayDateTime();
    $sql = "SELECT power.*,\n                   weather_filton.sol_rad AS sol_rad_filton,\n                   create_centre_meteo_raw.sol_rad AS sol_rad_cc\n            FROM power\n                LEFT JOIN weather_filton ON power.datetime = weather_filton.datetime\n                LEFT JOIN create_centre_meteo_raw ON power.datetime = create_centre_meteo_raw.datetime\n            WHERE (weather_filton.sol_rad > " . DECENT_SOLRAD_LIMIT . " OR\n                  create_centre_meteo_raw.sol_rad > " . DECENT_SOLRAD_LIMIT . ") AND\n                  DATE(power.datetime) = " . sqlDateString($dateTime);
    $result = $becDB->fetchQuery($sql);
    // Work out when sunrise and sunset are - we'll ignore any zero power readings close to them
    $timestamp = $dateTime->getTimestamp();
    $sunriseTime = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, FORECAST_IO_LAT, FORECAST_IO_LONG);
    $sunsetTime = date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, FORECAST_IO_LAT, FORECAST_IO_LONG);
    $ignoreWithin = 60 * 60;
    // One hour
    $anyHits = FALSE;
    foreach ($result as $entry) {
        $zeroMeterCount = 0;
        foreach ($becDB->getGenMeterArray() as $genMeter) {
            $dateTime = new DateTime($entry['datetime']);
            $timestamp = $dateTime->getTimestamp();
            # Note: The === below is necessary as otherwise NULL/uninitialised data would also match
            if ($entry[$genMeter] === 0 && $timestamp > $sunriseTime + $ignoreWithin && $timestamp < $sunsetTime - $ignoreWithin) {
                if (!$anyHits) {
                    $anyHits = TRUE;
                    ReportLog::append('Unexpected zero power output during ' . $dateTime->format('d/m/Y') . ":\n");
                    ReportLog::setError(TRUE);
                }
                if ($zeroMeterCount == 0) {
                    ReportLog::append('  Period ending [' . $dateTime->format('H:i') . " (UTC)]\tSolar radiation [CC: " . $entry['sol_rad_cc'] . ' Filton: ' . $entry['sol_rad_filton'] . "]: {$genMeter}");
                    $zeroMeterCount++;
                } else {
                    ReportLog::append(', ' . $genMeter);
                    $zeroMeterCount++;
                }
            }
        }
        if ($zeroMeterCount) {
            ReportLog::append("\n");
        }
    }
    if ($anyHits) {
        ReportLog::append("\n\n");
    } else {
        ReportLog::append('No unexpected zero power output readings yesterday (' . $dateTime->format('d/m/Y') . ")\n\n");
    }
    return $anyHits;
}
コード例 #9
0
 /**
  * Return true, false or null depending on whether the [opening hours]
  * value explicitly indicates an open, closed or undecided result.
  *
  * @param double $time A numeric value representing a time. If null, the
  *                     current time is used.
  *
  * @link   http://wiki.openstreetmap.org/wiki/Key:opening_hours
  * @return null|boolean
  */
 public function isOpen($time = null)
 {
     if ($this->value === null) {
         return null;
     }
     if ($this->value === '24/7') {
         return true;
     }
     if ($time === null) {
         $time = time();
     }
     if ($this->value === 'sunrise-sunset') {
         $start = $this->_startTime(date_sunrise($time));
         $end = $this->_endTime(date_sunset($time));
         $d = getdate($time);
         $ctime = $d['hours'] * 60 + $d['minutes'];
         return $ctime >= $start && $ctime <= $end;
     }
     // other simple test would be sunrise-sunset - with
     // offsets that would need to be taken into account
     // time specs...
     $rule_sequences = explode(';', $this->value);
     $day = strtolower(substr(date('D', $time), 0, 2));
     $retval = false;
     foreach ($rule_sequences as $rule_sequence) {
         $rule_sequence = strtolower(trim($rule_sequence));
         // If the day is explicitly specified in the rule sequence then
         // processing it takes precedence.
         if (preg_match('/' . $day . '/', $rule_sequence)) {
             // @fixme: brittle. use preg_replace with \w
             $portions = explode(' ', str_replace(', ', ',', $rule_sequence));
             return $this->_openTimeSpec($portions, $time);
         }
         // @fixme: brittle. use preg_replace with \w
         $portions = explode(' ', str_replace(', ', ',', $rule_sequence));
         $open = $this->_openTimeSpec($portions, $time);
         if ($open) {
             $retval = true;
         } elseif ($open === false) {
             $retval = false;
         }
     }
     return $retval;
 }
コード例 #10
0
ファイル: Weather.php プロジェクト: aaronpk/Atlas
 private static function _sunny($lat, $lng, $timezone)
 {
     // Get the beginning of the current day
     $now = new DateTime();
     if ($timezone) {
         $now->setTimeZone(new DateTimeZone($timezone));
     }
     $now->setTime(0, 0, 0);
     $now = $now->format('U');
     if ($lat !== null) {
         $sunrise = date_sunrise($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lng, 96);
         $sunset = date_sunset($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lng, 92);
         if ($sunrise < time() && time() < $sunset) {
             return 'day';
         } else {
             return 'night';
         }
     } else {
         return 'unknown';
     }
 }
コード例 #11
0
ファイル: weatherController.php プロジェクト: sergio11/teVeo
 public function getForecast($latitude, $longitude, $units)
 {
     $response = array("response_message" => array("type" => "RESPONSE", "name" => "WEATHER_FORECAST", "data" => array()));
     $url = self::API_ENDPOINT . self::API_KEY . '/';
     $url .= $latitude . ',' . $longitude . '?units=' . $units;
     $forecast = file_get_contents($url);
     //print_r($http_response_header);
     if (isset($http_response_header) && strpos($http_response_header[0], '200')) {
         $forecast = (array) json_decode($forecast, true);
         $time = $forecast["currently"]["time"];
         //timestamp del a salida del sol.
         $sunrise_timestamp = date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $forecast['latitude'], $forecast['longitude']);
         $sunset_timestamp = date_sunset($time, SUNFUNCS_RET_TIMESTAMP, $forecast['latitude'], $forecast['longitude']);
         //print_r($forecast);
         $forecast['currently']['sunrise_timestamp'] = $sunrise_timestamp;
         $forecast['currently']['sunset_timestamp'] = $sunset_timestamp;
         $response["response_message"]["data"] = array("error" => false, "msg" => array("forecast" => $forecast));
     } else {
         $response["response_message"]["data"] = array("error" => true, "msg" => array("msg" => "La previsión no se pudo obtener"));
     }
     return $response;
 }
コード例 #12
0
 /**
  * @param hcal_datetime $dt
  */
 public function __construct($dt)
 {
     $this->datetime = $dt;
     // $heb_date, $ts, $gmt_offset, $location, $now, $datetime =  null
     $ts = $dt->get_ts(false);
     $this->is_dst = false;
     $tz_offset = $dt->get_timezone_offset($this->is_dst);
     $ts -= $tz_offset;
     $this->gmt_offset = $tz_offset / 3600.0;
     $this->now = $dt->s / 3600.0 + $dt->m / 60.0 + $dt->h;
     $zenith = 90.0 + 50.0 / 60;
     $this->heb_date = $dt->get_hebrew_date_numeric();
     $this->location = $dt->location;
     $this->data = array();
     $lat = $this->location->latitude;
     $long = $this->location->longitude;
     $sunrise = date_sunrise($ts, SUNFUNCS_RET_DOUBLE, $lat, $long, $zenith, $this->gmt_offset);
     $sunset = date_sunset($ts, SUNFUNCS_RET_DOUBLE, $lat, $long, $zenith, $this->gmt_offset);
     $this->sunrise = $sunrise;
     $this->sunset = $sunset;
     $this->rel_hr = ($sunset - $sunrise) / 12.0;
     $this->is_chul = (bool) @$this->location->data['chul'];
     $this->calculate_base_times();
 }
コード例 #13
0
<?php

$taskLocation = realpath(dirname(__FILE__));
chdir($taskLocation);
include "../config.php";
$meteogram = array('location' => array('name' => 'Scampton', 'type' => 'Town', 'country' => "United Kingdom", 'timezone' => array('@attributes' => array('id' => "Europe/London", 'utcoffsetMinutes' => "0")), 'location' => array('@attributes' => array('altitude' => "", 'latitude' => "", 'longitude' => "", 'geobase' => "geonames", 'geobaseid' => "2643743"))), 'credit' => array('comment' => array("", ""), 'link' => array("@attributes" => array("text" => "Weather forecast from yr.no, delivered by the Norwegian Meteorological Institute and the NRK", "url" => "http://www.yr.no/place/United_Kingdom/England/London/"))), 'links' => array('link' => array(array('@attributes' => array('id' => "xmlSource", 'url' => "http://www.yr.no/place/United_Kingdom/England/London/forecast.xml")), array('@attributes' => array('id' => "xmlSourceHourByHour", 'url' => "http://www.yr.no/place/United_Kingdom/England/London/forecast_hour_by_hour.xml")), array('@attributes' => array('id' => "hourByHour", 'url' => "http://www.yr.no/place/United_Kingdom/England/London/hour_by_hour")), array('@attributes' => array('id' => "overview", 'url' => "http://www.yr.no/place/United_Kingdom/England/London/")), array('@attributes' => array('id' => "longTermForecast", 'url' => "http://www.yr.no/place/United_Kingdom/England/London/long")))), 'meta' => array('lastupdate' => "", 'nextupdate' => ""), 'sun' => array("@attributes" => array('rise' => "", 'set' => "")), 'forecast' => array('tabular' => array('time' => array())));
date_default_timezone_set(TZ);
if (date('I')) {
    $meteogram['location']['timezone']['@attributes']['utcoffsetMinutes'] = "60";
}
$meteogram['meta']['lastupdate'] = Date("Y-m-d\\TH:m:s");
$meteogram['meta']['nextupdate'] = Date("Y-m-d\\TH:m:s");
$meteogram['sun']['@attributes']['rise'] = Date("Y-m-d") . "T" . date_sunrise(time(), SUNFUNCS_RET_STRING, LAT, LONG, 90 + 60 / 60, 0);
$meteogram['sun']['@attributes']['set'] = Date("Y-m-d") . "T" . date_sunset(time(), SUNFUNCS_RET_STRING, LAT, LONG, 90, 0);
$meteogram['location']['location']['@attributes']['altitude'] = ALTITUDE;
$meteogram['location']['location']['@attributes']['latitude'] = LAT;
$meteogram['location']['location']['@attributes']['longitude'] = LONG;
//die($meteogram['location']['timezone'] ['@attributes']);
$meteogram['location']['timezone']['@attributes']['id'] = TZ;
$link = mysql_connect(SERVER, USER, PASSWORD);
$db_found = mysql_select_db(DATABASE);
$sql = "SELECT * FROM Weather.meteogram " . "WHERE `from` >= now() - INTERVAL 49 HOUR GROUP BY DATE_FORMAT(`from`, \"%d-%m-%y %H:00\");";
$query = mysql_query($sql);
$tabularContent = "";
$time = array(['@attributes'] => array(['from'] => "0", ['to'] => "0"), ['comment'] => array(), ['symbol'] => array(['@attributes'] => array(['number'] => "2", ['numberEx'] => "02", ['name'] => "Fair", ['var'] => "02d")), ['precipitation'] => array(['@attributes'] => array(['value'] => "0")), ['windDirection'] => array(['@attributes'] => array(['deg'] => "0", ['code'] => "0", ['name'] => "0")), ['windSpeed'] => array(['@attributes'] => array(['mps'] => "0", ['name'] => "")), ['temperature'] => array(['@attributes'] => array(['unit'] => "celcius", ['value'] => "0")), ['pressure'] => array(['@attributes'] => array(['unit'] => "hPa", ['value'] => "0")));
while ($r = mysql_fetch_array($query)) {
    $time['@attributes']['from'] = $r['from'];
    $time['@attributes']['to'] = $r['to'];
    $time['comment'] = array("", "");
    $time['symbol']['@attributes']['number'] = "";
    $time['symbol']['@attributes']['numberEx'] = "";
コード例 #14
0
ファイル: huntingTimes.php プロジェクト: spprichard/pric3ste
	<h1>When should Marty hunt?</h1>
	

	<?php 
/* calculate the sunrise time for Lisbon, Portugal
	 Latitude: 47.4736 North
	 Longitude: 94.8803 West
	 Zenith ~= 90
	 timezone: GMT -06
	 */
date_default_timezone_set('America/Chicago');
//print "Today is ";
//print date("D, M j G:i:s T Y");
print "<br />Current Time is: ";
print date("g:i A");
//print "Sunrei"
//print date_sunrise( time(), SUNFUNCS_RET_STRING,47.4736,94.8803,90,-06);
print "<br />Sunrise time : ";
print date("g: i A", date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, 47.4736, -94.88030000000001, 90, -06));
print "<br /> Start Hunting at: ";
print date("g:i A", date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, 47.4736, -94.88030000000001, 90, -06) - 1800);
print "<br/> Sunset Time: ";
print date("g:i A", date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, 47.4736, -94.88030000000001, 90, -6));
print "<br/> Stop hunting at: ";
print date("g:i A", date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, 47.4736, -94.88030000000001, 90, -6) + 1800);
?>
	
</body>

</html>
コード例 #15
0
function getSunrise($format)
{
    global $schedulePars;
    return date_sunrise(time(), $format, $schedulePars[SCHEDULE_LATITUDE], $schedulePars[SCHEDULE_LONGTITUDE], SCHEDULE_ZENITH, getTimeOffset());
}
コード例 #16
0
ファイル: home.sun.php プロジェクト: bangnaga/HomeOverlord
<?php

$tzOffset = date('O') / 100;
?>
<pre>
  Date: <?php 
echo date('Y-m-d H:i');
?>
 
  UTC Offset: <?php 
echo $tzOffset;
?>
 
  Sunset: <?php 
echo date_sunset(time(), SUNFUNCS_RET_STRING, $GLOBALS['config']['geo']['lat'], $GLOBALS['config']['geo']['long'], $GLOBALS['config']['geo']['zenith'], $tzOffset);
?>
 
  Sunrise: <?php 
echo date_sunrise(time(), SUNFUNCS_RET_STRING, $GLOBALS['config']['geo']['lat'], $GLOBALS['config']['geo']['long'], $GLOBALS['config']['geo']['zenith'], $tzOffset);
?>
 

</pre>
コード例 #17
0
			</form>
			<?php 
echo '<table>';
echo '<thead>';
echo '<tr>';
echo '</tr>';
echo '</thead>';
if (isset($_POST['latitude']) && isset($_POST['longitude'])) {
    date_default_timezone_set('UTC');
    $lat = $_POST['latitude'];
    $long = $_POST['longitude'];
    $now = time();
    echo '<div>' . date_sunrise($now, SUNFUNCS_RET_STRING, $lat, $long) . '</div>';
    echo '<div>' . date_sunset($now, SUNFUNCS_RET_STRING, $lat, $long) . '</div>';
    for ($day = 0; $day <= 6; $day++) {
        echo '<tr>';
        $timestamp = $now + $day * 86400;
        $row = array();
        $row[] = date('M d', $timestamp);
        $row[] = date_sunrise($timestamp, SUNFUNCS_RET_STRING, $lat, $long, 97.5);
        $row[] = date_sunrise($timestamp, SUNFUNCS_RET_STRING, $lat, $long);
        $row[] = date_sunset($timestamp, SUNFUNCS_RET_STRING, $lat, $long);
        $row[] = date_sunset($timestamp, SUNFUNCS_RET_STRING, $lat, $long, 97.5);
        echo '<td>' . implode('</td><td>', $row) . '</td>';
        echo '</tr>';
    }
}
echo '</table>';
?>
        </body>
</html>
コード例 #18
0
 /**
  * Calculates the sunrise or sunset based on a location
  *
  * @param  array  $location  Location for calculation MUST include 'latitude', 'longitude', 'horizon'
  * @param  bool   $horizon   true: sunrise; false: sunset
  * @return mixed  - false: midnight sun, integer:
  */
 protected function calcSun($location, $horizon, $rise = false)
 {
     // timestamp within 32bit
     if (abs($this->_unixTimestamp) <= 0x7fffffff) {
         if ($rise === false) {
             return date_sunset($this->_unixTimestamp, SUNFUNCS_RET_TIMESTAMP, $location['latitude'], $location['longitude'], 90 + $horizon, $this->_offset / 3600);
         }
         return date_sunrise($this->_unixTimestamp, SUNFUNCS_RET_TIMESTAMP, $location['latitude'], $location['longitude'], 90 + $horizon, $this->_offset / 3600);
     }
     // self calculation - timestamp bigger than 32bit
     // fix circle values
     $quarterCircle = 0.5 * M_PI;
     $halfCircle = M_PI;
     $threeQuarterCircle = 1.5 * M_PI;
     $fullCircle = 2 * M_PI;
     // radiant conversion for coordinates
     $radLatitude = $location['latitude'] * $halfCircle / 180;
     $radLongitude = $location['longitude'] * $halfCircle / 180;
     // get solar coordinates
     $tmpRise = $rise ? $quarterCircle : $threeQuarterCircle;
     $radDay = $this->date('z', $this->_unixTimestamp) + ($tmpRise - $radLongitude) / $fullCircle;
     // solar anomoly and longitude
     $solAnomoly = $radDay * 0.017202 - 0.0574039;
     $solLongitude = $solAnomoly + 0.0334405 * sin($solAnomoly);
     $solLongitude += 4.93289 + 0.000349066 * sin(2 * $solAnomoly);
     // get quadrant
     $solLongitude = $this->_range($solLongitude, $fullCircle);
     if ($solLongitude / $quarterCircle - intval($solLongitude / $quarterCircle) == 0) {
         $solLongitude += 4.84814E-6;
     }
     // solar ascension
     $solAscension = sin($solLongitude) / cos($solLongitude);
     $solAscension = atan2(0.9174600000000001 * $solAscension, 1);
     // adjust quadrant
     if ($solLongitude > $threeQuarterCircle) {
         $solAscension += $fullCircle;
     } else {
         if ($solLongitude > $quarterCircle) {
             $solAscension += $halfCircle;
         }
     }
     // solar declination
     $solDeclination = 0.39782 * sin($solLongitude);
     $solDeclination /= sqrt(-$solDeclination * $solDeclination + 1);
     $solDeclination = atan2($solDeclination, 1);
     $solHorizon = $horizon - sin($solDeclination) * sin($radLatitude);
     $solHorizon /= cos($solDeclination) * cos($radLatitude);
     // midnight sun, always night
     if (abs($solHorizon) > 1) {
         return false;
     }
     $solHorizon /= sqrt(-$solHorizon * $solHorizon + 1);
     $solHorizon = $quarterCircle - atan2($solHorizon, 1);
     if ($rise) {
         $solHorizon = $fullCircle - $solHorizon;
     }
     // time calculation
     $localTime = $solHorizon + $solAscension - 0.0172028 * $radDay - 1.73364;
     $universalTime = $localTime - $radLongitude;
     // determinate quadrant
     $universalTime = $this->_range($universalTime, $fullCircle);
     // radiant to hours
     $universalTime *= 24 / $fullCircle;
     // convert to time
     $hour = intval($universalTime);
     $universalTime = ($universalTime - $hour) * 60;
     $min = intval($universalTime);
     $universalTime = ($universalTime - $min) * 60;
     $sec = intval($universalTime);
     return $this->mktime($hour, $min, $sec, $this->date('m', $this->_unixTimestamp), $this->date('j', $this->_unixTimestamp), $this->date('Y', $this->_unixTimestamp), -1, true);
 }
コード例 #19
0
<?php

$taskLocation = realpath(dirname(__FILE__));
chdir($taskLocation);
include "../config.php";
$file = file_get_contents("templates/metrogram-template.xml");
date_default_timezone_set(TZ);
if (date('I')) {
    $file = str_replace("[--UTCOFFSET--]", 60, $file);
} else {
    $file = str_replace("[--UTCOFFSET--]", 0, $file);
}
$file = str_replace("[--sunrise--]", Date("Y-m-d") . "T" . date_sunrise(time(), SUNFUNCS_RET_STRING, LAT, LONG, 90 + 60 / 60, 0) . ":00", $file);
$file = str_replace("[--sunset--]", Date("Y-m-d") . "T" . date_sunset(time(), SUNFUNCS_RET_STRING, LAT, LONG, 90, 0) . ":00", $file);
$file = str_replace("[--LAT--]", LAT, $file);
$file = str_replace("[--LONG--]", LONG, $file);
$file = str_replace("[--ALTITUDE--]", ALTITUDE, $file);
$link = mysql_connect(SERVER, USER, PASSWORD);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_found = mysql_select_db(DATABASE);
$sql = "SELECT * FROM Weather.meteogram\nWHERE `from` >= now() - INTERVAL 48 HOUR GROUP BY hour(`from`) ORDER BY `from` DESC;";
$query = mysql_query($sql);
$tabularContent = "";
$rowtemplate = file_get_contents("templates/metrogram-rowdata-template.xml");
while ($r = mysql_fetch_array($query)) {
    $rowdata = $rowtemplate;
    $rowdata = str_replace("[--precipitation--]", $r['precipitation'], $rowdata);
    $rowdata = str_replace("[--deg--]", $r['deg'], $rowdata);
    $rowdata = str_replace("[--code--]", $r['code'], $rowdata);
コード例 #20
0
ファイル: task6.php プロジェクト: LidiyaIvancheva/PHP_hw1
<?php 
//Calculate the sunrise time for Brazil, Sao Paulo
//Latitude: 23.533773 South
//Longitude: 46.625290 West
//Zenith ~= 90
//offset: +1 GMT
echo "<h2>America, Brazil (Sao Paulo city) </h2>";
echo "Date: " . date("M d Y");
echo "<br>Sunrise time: ";
echo date_sunrise(time(), SUNFUNCS_RET_STRING, 23.5, -9, 90, 1);
echo "<br>Sunset time: ";
echo date_sunset(time(), SUNFUNCS_RET_STRING, 46.6, -9, 90, 1);
echo "<br>";
date_default_timezone_set('America/Sao_Paulo');
echo "The current tme is " . date("h:i:sa");
コード例 #21
0
ファイル: date_sunrise_test.php プロジェクト: badlamer/hhvm
//Initialise the variables
$time = mktime(0, 0, 0, 12, 26, 2012);
$latitude = 38.4;
$longitude = -9;
$zenith = 90;
$gmt_offset = 1;
echo "\n-- Testing date_sunrise() function by passing one parameter --\n";
var_dump(date_sunrise($time));
echo "\n-- Testing date_sunrise() function by passing two parameters --\n";
var_dump(date_sunrise($time, SUNFUNCS_RET_STRING));
var_dump(date_sunrise($time, SUNFUNCS_RET_DOUBLE));
var_dump(date_sunrise($time, SUNFUNCS_RET_TIMESTAMP));
echo "\n-- Testing date_sunrise() function by passing two parameters --\n";
var_dump(date_sunrise($time, SUNFUNCS_RET_STRING, $latitude));
var_dump(date_sunrise($time, SUNFUNCS_RET_DOUBLE, $latitude));
var_dump(date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $latitude));
echo "\n-- Testing date_sunrise() function by passing three  parameters --\n";
var_dump(date_sunrise($time, SUNFUNCS_RET_STRING, $latitude, $longitude));
var_dump(date_sunrise($time, SUNFUNCS_RET_DOUBLE, $latitude, $longitude));
var_dump(date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude));
echo "\n-- Testing date_sunrise() function by passing four parameters --\n";
var_dump(date_sunrise($time, SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith));
var_dump(date_sunrise($time, SUNFUNCS_RET_DOUBLE, $latitude, $longitude, $zenith));
var_dump(date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith));
echo "\n-- Testing date_sunrise() function by passing five parameters --\n";
var_dump(date_sunrise($time, SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith, $gmt_offset));
var_dump(date_sunrise($time, SUNFUNCS_RET_DOUBLE, $latitude, $longitude, $zenith, $gmt_offset));
var_dump(date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith, $gmt_offset));
?>
===DONE===
コード例 #22
0
 function get_sundata($which, $lat, $lon, $off)
 {
     $off += 500;
     if ($which == "sunrise") {
         $sun = date_sunrise(gmmktime(), SUNFUNCS_RET_DOUBLE, $lat, $lon);
     } else {
         $sun = date_sunset(gmmktime(), SUNFUNCS_RET_DOUBLE, $lat, $lon);
     }
     $sun += $off / 100;
     if ($sun < 0) {
         $sun += 24;
     }
     if ($sun >= 24) {
         $sun -= 24;
     }
     $ampm = "AM";
     if ($sun >= 12.0) {
         $ampm = "PM";
     }
     if ($sun >= 13.0) {
         $sun -= 12.0;
     }
     if ($sun <= 1.0) {
         $sun += 12.0;
     }
     $minutes = $sun - intval($sun);
     $minutes *= 60;
     return intval($sun) . ":" . sprintf("%02d", intval($minutes)) . " " . $ampm;
     //return $sun;
 }
コード例 #23
0
ファイル: includes.php プロジェクト: anderssjoeberg/andrixTNG
function GetGryning()
{
    connectdb();
    $sql = "SELECT * from settings WHERE label=longitud";
    $result = mysql_query($sql);
    $longitud = mysql_result($result, "value");
    $sql = "SELECT * from settings WHERE label=latitud";
    $result = mysql_query($sql);
    $latitud = mysql_result($result, "latitud");
    $sql = "SELECT * from settings WHERE label=tidzon";
    $result = mysql_query($sql);
    $timezone = mysql_result($result, "value");
    $zenith = 90 + 50 / 60;
    $twilightZenith = 96;
    $time = date_sunrise(time(), SUNFUNCS_RET_STRING, $latitud, $longitud, $twilightZenith, $timezone);
    return $time;
}
コード例 #24
0
ファイル: helper.php プロジェクト: grchis/Site-Auto
 function icon($icon, $size = 128, $font = false)
 {
     // creating JURI instance
     $uri =& JURI::getInstance();
     $icon_path = $uri->root() . 'modules/mod_weather_gk4/icons/' . $this->config['iconset'] . '/' . ($size == 128 ? '' : $size . '/');
     if ($this->config['iconset'] != 'yahoo') {
         // if selected icon exists
         if (is_array($this->icons[$icon])) {
             // if user use PHP5 and google feed
             if (function_exists('date_sunrise') && function_exists('date_sunset') && $this->config['source'] == 'google') {
                 // if user set values for his position
                 if ($this->config['latitude'] !== 'null' && $this->config['longitude'] !== 'null') {
                     // getting informations about sunrise and sunset time
                     $sunrise = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $this->config['latitude'], $this->config['longitude'], ini_get("date.sunrise_zenith"), $this->config['timezone']) + $this->config['t_offset'] * 3600;
                     $sunset = date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, $this->config['latitude'], $this->config['longitude'], ini_get("date.sunrise_zenith"), $this->config['timezone']) + $this->config['t_offset'] * 3600;
                     // flag for night ;)
                     $night = false;
                     // night check ;)
                     if (time() < $sunrise || time() > $sunset) {
                         $night = true;
                         // now is night! :P
                     }
                     // getting final icon - if selected icon has two icons - for day and night - return correct icon
                     if ($font) {
                         return $this->icons[$icon][count($this->icons[$icon]) > 1 && $night ? 1 : 0];
                     }
                     return $icon_path . $this->icons[$icon][count($this->icons[$icon]) > 1 && $night ? 1 : 0];
                 } else {
                     if ($font) {
                         return $this->icons[$icon][0];
                     }
                     return $icon_path . $this->icons[$icon][0];
                 }
             } else {
                 if ($this->config['source'] == 'yahoo' && isset($this->parsedData['sunrise']) && isset($this->parsedData['sunset'])) {
                     $sunrise = $this->prepareTime($this->parsedData['sunrise']) + $this->config['t_offset'] * 3600;
                     $sunset = $this->prepareTime($this->parsedData['sunset']) + $this->config['t_offset'] * 3600;
                     // flag for night ;)
                     $night = false;
                     // night check ;)
                     if (time() < $sunrise || time() > $sunset) {
                         $night = true;
                         // now is night! :P
                     }
                     if ($font) {
                         return $this->icons[$icon][count($this->icons[$icon]) > 1 && $night ? 1 : 0];
                     }
                     // getting final icon - if selected icon has two icons - for day and night - return correct icon
                     return $icon_path . $this->icons[$icon][count($this->icons[$icon]) > 1 && $night ? 1 : 0];
                 } else {
                     if ($font) {
                         return $this->icons[$icon][0];
                     }
                     return $icon_path . $this->icons[$icon][0];
                 }
             }
         } else {
             // else - return "?" icon
             if ($font) {
                 return 'other.png';
             }
             return $icon_path . 'other.png';
         }
     } else {
         return 'http://l.yimg.com/a/i/us/we/52/' . $icon . '.gif';
     }
 }
コード例 #25
0
function yrno_date_line($time)
{
    global $latitude, $longitude, $rowColor, $timeFormat, $imgDir, $srise, $sset, $cols;
    $srise = date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude);
    // standard time integer
    $sset = date_sunset($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude);
    $dlength = $sset - $srise;
    $dlengthHr = floor($dlength / 3600);
    $dlengthMin = round(($dlength - 3600 * $dlengthHr) / 60);
    $strDayLength = $dlengthHr . ':' . substr('00' . $dlengthMin, -2);
    $longDate = yrno_long_date($time);
    $string = '<tr class="dateline ' . $rowColor . '"><td colspan="' . $cols . '">
<span style="float:left; position:relative;">&nbsp;<b>' . $longDate . '</b></span>
<span style="float:right;position:relative;">
	<span class="rTxt">
		<img src="' . $imgDir . '/sunrise.png" width="24" height="12" alt="sunrise" />&nbsp;&nbsp;' . date($timeFormat, $srise) . '&nbsp;&nbsp;
		<img src="' . $imgDir . '/sunset.png"  width="24" height="12" alt="sunset" />&nbsp;&nbsp;' . date($timeFormat, $sset) . '&nbsp;&nbsp;&nbsp;' . yrnotransstr('Daylength') . ': ' . $strDayLength . '&nbsp;
	</span>
</span>
</td></tr>' . PHP_EOL;
    if ($rowColor == 'row-dark') {
        $rowColor = 'row-light';
    } else {
        $rowColor = 'row-dark';
    }
    return $string;
}
コード例 #26
0
ファイル: Wwo.php プロジェクト: Gomez/horde
 /**
  * Populates some common data used by forecasts and current conditions.
  * Weather Underground allows requesting multiple features per request,
  * and only counts it as a single request against your API key. So we trade
  * a bit of request time/traffic for a smaller number of requests to obtain
  * information for e.g., a typical weather portal display.
  *
  * @param string $location  The location identifier.
  * @param integer $length   The forecast length.
  */
 protected function _getCommonElements($location, $length = Horde_Service_Weather::FORECAST_5DAY)
 {
     if (!empty($this->_current) && $location == $this->_lastLocation && $this->_lastLength == $length) {
         return;
     }
     $this->_lastLength = $length;
     $this->_lastLocation = $location;
     $url = new Horde_Url(self::API_URL);
     // Not sure why, but Wwo chokes if we urlencode the location?
     $url->add(array('q' => $location, 'num_of_days' => $length, 'includeLocation' => 'yes', 'timezone' => 'yes', 'extra' => 'localObsTime'));
     $results = $this->_makeRequest($url);
     // Use the minimum station data provided by forecast request to
     // fetch the full station data.
     $station = $this->_parseStation($results->data->nearest_area[0]);
     $station = $this->searchLocations($station->lat . ',' . $station->lon);
     // Hack some data to allow UTC observation time to be returned.
     $results->data->current_condition[0]->date = new Horde_Date($results->data->current_condition[0]->localObsDateTime);
     $results->data->current_condition[0]->date->hour += -$station->getOffset();
     // Parse it.
     $this->_current = $this->_parseCurrent($results->data->current_condition);
     // Sunrise/Sunset
     $date = $this->_current->time;
     $station->sunset = new Horde_Date(date_sunset($date->timestamp(), SUNFUNCS_RET_TIMESTAMP, $station->lat, $station->lon));
     $station->sunrise = new Horde_Date(date_sunrise($date->timestamp(), SUNFUNCS_RET_TIMESTAMP, $station->lat, $station->lon));
     $station->time = (string) $date;
     $this->_station = $station;
     $this->_forecast = $this->_parseForecast($results->data->weather);
 }
コード例 #27
0
ファイル: sunfuncts.php プロジェクト: badlamer/hhvm
<?php

date_default_timezone_set('Asia/Jerusalem');
for ($a = 1; $a <= 12; $a++) {
    echo date_sunrise(mktime(1, 1, 1, $a, 1, 2003), SUNFUNCS_RET_TIMESTAMP, 31.7667, 35.2333, 90.83, 2) . " ";
    echo date_sunrise(mktime(1, 1, 1, $a, 1, 2003), SUNFUNCS_RET_STRING, 31.7667, 35.2333, 90.83, 2) . " ";
    echo date_sunrise(mktime(1, 1, 1, $a, 1, 2003), SUNFUNCS_RET_DOUBLE, 31.7667, 35.2333, 90.83, 2) . "\n";
    echo date_sunset(mktime(1, 1, 1, $a, 1, 2003), SUNFUNCS_RET_TIMESTAMP, 31.7667, 35.2333, 90.83, 2) . " ";
    echo date_sunset(mktime(1, 1, 1, $a, 1, 2003), SUNFUNCS_RET_STRING, 31.7667, 35.2333, 90.83, 2) . " ";
    echo date_sunset(mktime(1, 1, 1, $a, 1, 2003), SUNFUNCS_RET_DOUBLE, 31.7667, 35.2333, 90.83, 2) . "\n";
}
コード例 #28
0
ファイル: server.php プロジェクト: bclark00/boxio
 private function checkSun()
 {
     $res = $this->mysqli->query("SELECT * FROM view_configuration");
     while ($conf_array = $res->fetch_assoc()) {
         $lat = $conf_array['GPS_latitude'];
         $lng = $conf_array['GPS_longitude'];
     }
     if (!isset($lat, $lng) || $lat == NULL || $lng == NULL) {
         $lat = $this->def->DEFAULT_LAT;
         $lng = $this->def->DEFAULT_LNG;
     }
     $sunset_timestamp = date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $lng);
     $res = $this->mysqli->query("UPDATE cron SET \r\n\t\tminutes=" . date('i', $sunset_timestamp) . ", \r\n\t\theures=" . date('H', $sunset_timestamp) . "\r\n\t\tWHERE sunset=1");
     $sunrise_timestamp = date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $lng);
     $res = $this->mysqli->query("UPDATE cron SET \r\n\t\tminutes=" . date('i', $sunrise_timestamp) . ", \r\n\t\theures=" . date('H', $sunrise_timestamp) . "\r\n\t\tWHERE sunrise=1");
 }
コード例 #29
0
// if ( isset($debug) ) {
if ($debug) {
    echo "dateTimeUTC: ";
    print_r($dateTimeUTC);
    //	echo "something: $something\n";
    echo "dateOff: {$dateOff}\n";
}
//offical = 90 degrees 50' 90.8333 (gk: this is the "official" number to determine sunrise & sunset)
//civil = 96 degrees (gk: this is the number to obtain civilian twilight times - horizon may be visible)
//nautical = 102 degrees (gk: this is the number to obtain nautical twilight - the horizon is not visible)
//astronomical = 108 degrees (gk: this is the number for astronomical twilight - starts at sunset).
//$zenith = 108;
// Higher is sooner sunrise
//$zenithRise = 96;
$zenithRise = 102;
// Higher is later sunset
//$zenithSet = 96;
$zenithSet = 102;
$sunrise = date_sunrise($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lon, $zenithRise, $hours);
$sunset = date_sunset($now, SUNFUNCS_RET_TIMESTAMP, $lat, $lon, $zenithSet, $hours);
echo "Sunrise: " . $sunrise . "\n";
echo "Sunset: " . $sunset . "\n";
if (isset($doPretty)) {
    $nowPretty = date('Y-m-d g:i:sa', $now);
    $sunrisePretty = date('Y-m-d g:i:sa', $sunrise);
    $sunsetPretty = date('Y-m-d g:i:sa', $sunset);
    echo "now: {$now}\n";
    echo "nowPretty: {$nowPretty}\n";
    echo "sunrisePretty: {$sunrisePretty}\n";
    echo "sunsetPretty: {$sunsetPretty}\n";
}
コード例 #30
0
 /**
  * Calculates sunrise and sunset for a location
  *
  * The sun position algorithm taken from the 'US Naval Observatory's
  * Almanac for Computers', implemented by Ken Bloom <kekabloom[at]ucdavis[dot]edu>
  * for the zmanim project, converted to C by Moshe Doron <mosdoron[at]netvision[dot]net[dot]il>
  * and finally taken from the PHP5 sources and converted to native PHP as a wrapper.
  *
  * The date has to be entered as a timestamp!
  *
  * @param   int                         $date
  * @param   int                         $retformat
  * @param   float                       $latitude
  * @param   float                       $longitude
  * @param   float                       $zenith
  * @param   float                       $gmt_offset
  * @param   bool                        $sunrise
  * @return  PEAR_Error|mixed
  * @throws  PEAR_Error::SERVICES_WEATHER_ERROR_SUNFUNCS_DATE_INVALID
  * @throws  PEAR_Error::SERVICES_WEATHER_ERROR_SUNFUNCS_RETFORM_INVALID
  * @throws  PEAR_Error::SERVICES_WEATHER_ERROR_UNKNOWN_ERROR
  * @access  public
  */
 function calculateSunRiseSet($date, $retformat = null, $latitude = null, $longitude = null, $zenith = null, $gmt_offset = null, $sunrise = true)
 {
     // Date must be timestamp for now
     if (!is_int($date)) {
         return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_SUNFUNCS_DATE_INVALID, __FILE__, __LINE__);
     }
     // Check for proper return format
     if ($retformat === null) {
         $retformat = SUNFUNCS_RET_STRING;
     } elseif (!in_array($retformat, array(SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, SUNFUNCS_RET_DOUBLE))) {
         return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_SUNFUNCS_RETFORM_INVALID, __FILE__, __LINE__);
     }
     // Set default values for coordinates
     if ($latitude === null) {
         $latitude = SUNFUNCS_DEFAULT_LATITUDE;
     } else {
         $latitude = (double) $latitude;
     }
     if ($longitude === null) {
         $longitude = SUNFUNCS_DEFAULT_LONGITUDE;
     } else {
         $longitude = (double) $longitude;
     }
     if ($zenith === null) {
         if ($sunrise) {
             $zenith = SUNFUNCS_SUNRISE_ZENITH;
         } else {
             $zenith = SUNFUNCS_SUNSET_ZENITH;
         }
     } else {
         $zenith = (double) $zenith;
     }
     // Default value for GMT offset
     if ($gmt_offset === null) {
         $gmt_offset = date("Z", $date) / 3600;
     } else {
         $gmt_offset = (double) $gmt_offset;
     }
     // If we have PHP5, then act as wrapper for the appropriate functions
     if ($sunrise && function_exists("date_sunrise")) {
         return date_sunrise($date, $retformat, $latitude, $longitude, $zenith, $gmt_offset);
     }
     if (!$sunrise && function_exists("date_sunset")) {
         return date_sunset($date, $retformat, $latitude, $longitude, $zenith, $gmt_offset);
     }
     // Apparently we have PHP4, so calculate the neccessary steps in native PHP
     // Step 1: First calculate the day of the year
     $N = date("z", $date) + 1;
     // Step 2: Convert the longitude to hour value and calculate an approximate time
     $lngHour = $longitude / 15;
     // Use 18 for sunset instead of 6
     if ($sunrise) {
         // Sunrise
         $t = $N + (6 - $lngHour) / 24;
     } else {
         // Sunset
         $t = $N + (18 - $lngHour) / 24;
     }
     // Step 3: Calculate the sun's mean anomaly
     $M = 0.9856 * $t - 3.289;
     // Step 4: Calculate the sun's true longitude
     $L = $M + 1.916 * sin(deg2rad($M)) + 0.02 * sin(deg2rad(2 * $M)) + 282.634;
     while ($L < 0) {
         $Lx = $L + 360;
         assert($Lx != $L);
         // askingtheguru: really needed?
         $L = $Lx;
     }
     while ($L >= 360) {
         $Lx = $L - 360;
         assert($Lx != $L);
         // askingtheguru: really needed?
         $L = $Lx;
     }
     // Step 5a: Calculate the sun's right ascension
     $RA = rad2deg(atan(0.91764 * tan(deg2rad($L))));
     while ($RA < 0) {
         $RAx = $RA + 360;
         assert($RAx != $RA);
         // askingtheguru: really needed?
         $RA = $RAx;
     }
     while ($RA >= 360) {
         $RAx = $RA - 360;
         assert($RAx != $RA);
         // askingtheguru: really needed?
         $RA = $RAx;
     }
     // 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
     $RA /= 15;
     // Step 6: Calculate the sun's declination
     $sinDec = 0.39782 * sin(deg2rad($L));
     $cosDec = cos(asin($sinDec));
     // Step 7a: Calculate the sun's local hour angle
     $cosH = (cos(deg2rad($zenith)) - $sinDec * sin(deg2rad($latitude))) / ($cosDec * cos(deg2rad($latitude)));
     // XXX: What's the use of this block.. ?
     // if (sunrise && cosH > 1 || !sunrise && cosH < -1) {
     //     throw doesnthappen();
     // }
     // Step 7b: Finish calculating H and convert into hours
     if ($sunrise) {
         // Sunrise
         $H = 360 - rad2deg(acos($cosH));
     } else {
         // Sunset
         $H = rad2deg(acos($cosH));
     }
     $H = $H / 15;
     // Step 8: Calculate local mean time
     $T = $H + $RA - 0.06571 * $t - 6.622;
     // Step 9: Convert to UTC
     $UT = $T - $lngHour;
     while ($UT < 0) {
         $UTx = $UT + 24;
         assert($UTx != $UT);
         // askingtheguru: really needed?
         $UT = $UTx;
     }
     while ($UT >= 24) {
         $UTx = $UT - 24;
         assert($UTx != $UT);
         // askingtheguru: really needed?
         $UT = $UTx;
     }
     $UT = $UT + $gmt_offset;
     // Now bring the result into the chosen format and return
     switch ($retformat) {
         case SUNFUNCS_RET_TIMESTAMP:
             return intval($date - $date % (24 * 3600) + 3600 * $UT);
         case SUNFUNCS_RET_STRING:
             $N = floor($UT);
             return sprintf("%02d:%02d", $N, floor(60 * ($UT - $N)));
         case SUNFUNCS_RET_DOUBLE:
             return $UT;
         default:
             return Services_Weather::raiseError(SERVICES_WEATHER_ERROR_UNKNOWN_ERROR, __FILE__, __LINE__);
     }
 }