Current File : /home/k/a/r/karenpetzb/www/items/category/Date.tar |
DateObject.php 0000604 00000112422 15071442100 0007251 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: DateObject.php 13319 2008-12-16 09:27:04Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Date
* @subpackage Zend_Date_DateObject
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Date_DateObject {
/**
* UNIX Timestamp
*/
private $_unixTimestamp;
protected static $_cache = null;
protected static $_defaultOffset = 0;
/**
* active timezone
*/
private $_timezone = 'UTC';
private $_offset = 0;
private $_syncronised = 0;
// turn off DST correction if UTC or GMT
protected $_dst = true;
/**
* Table of Monthdays
*/
private static $_monthTable = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
/**
* Table of Years
*/
private static $_yearTable = array(
1970 => 0, 1960 => -315619200, 1950 => -631152000,
1940 => -946771200, 1930 => -1262304000, 1920 => -1577923200,
1910 => -1893456000, 1900 => -2208988800, 1890 => -2524521600,
1880 => -2840140800, 1870 => -3155673600, 1860 => -3471292800,
1850 => -3786825600, 1840 => -4102444800, 1830 => -4417977600,
1820 => -4733596800, 1810 => -5049129600, 1800 => -5364662400,
1790 => -5680195200, 1780 => -5995814400, 1770 => -6311347200,
1760 => -6626966400, 1750 => -6942499200, 1740 => -7258118400,
1730 => -7573651200, 1720 => -7889270400, 1710 => -8204803200,
1700 => -8520336000, 1690 => -8835868800, 1680 => -9151488000,
1670 => -9467020800, 1660 => -9782640000, 1650 => -10098172800,
1640 => -10413792000, 1630 => -10729324800, 1620 => -11044944000,
1610 => -11360476800, 1600 => -11676096000);
/**
* Set this object to have a new UNIX timestamp.
*
* @param string|integer $timestamp OPTIONAL timestamp; defaults to local time using time()
* @return string|integer old timestamp
* @throws Zend_Date_Exception
*/
protected function setUnixTimestamp($timestamp = null)
{
$old = $this->_unixTimestamp;
if (is_numeric($timestamp)) {
$this->_unixTimestamp = $timestamp;
} else if ($timestamp === null) {
$this->_unixTimestamp = time();
} else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('\'' . $timestamp . '\' is not a valid UNIX timestamp', $timestamp);
}
return $old;
}
/**
* Returns this object's UNIX timestamp
* A timestamp greater then the integer range will be returned as string
* This function does not return the timestamp as object. Use copy() instead.
*
* @return integer|string timestamp
*/
protected function getUnixTimestamp()
{
if ($this->_unixTimestamp === intval($this->_unixTimestamp)) {
return (int) $this->_unixTimestamp;
} else {
return (string) $this->_unixTimestamp;
}
}
/**
* Internal function.
* Returns time(). This method exists to allow unit tests to work-around methods that might otherwise
* be hard-coded to use time(). For example, this makes it possible to test isYesterday() in Date.php.
*
* @param integer $sync OPTIONAL time syncronisation value
* @return integer timestamp
*/
protected function _getTime($sync = null)
{
if ($sync !== null) {
$this->_syncronised = round($sync);
}
return (time() + $this->_syncronised);
}
/**
* Internal mktime function used by Zend_Date.
* The timestamp returned by mktime() can exceed the precision of traditional UNIX timestamps,
* by allowing PHP to auto-convert to using a float value.
*
* Returns a timestamp relative to 1970/01/01 00:00:00 GMT/UTC.
* DST (Summer/Winter) is depriciated since php 5.1.0.
* Year has to be 4 digits otherwise it would be recognised as
* year 70 AD instead of 1970 AD as expected !!
*
* @param integer $hour
* @param integer $minute
* @param integer $second
* @param integer $month
* @param integer $day
* @param integer $year
* @param boolean $gmt OPTIONAL true = other arguments are for UTC time, false = arguments are for local time/date
* @return integer|float timestamp (number of seconds elapsed relative to 1970/01/01 00:00:00 GMT/UTC)
*/
protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt = false)
{
// complete date but in 32bit timestamp - use PHP internal
if ((1901 < $year) and ($year < 2038)) {
$oldzone = @date_default_timezone_get();
// Timezone also includes DST settings, therefor substracting the GMT offset is not enough
// We have to set the correct timezone to get the right value
if (($this->_timezone != $oldzone) and ($gmt === false)) {
date_default_timezone_set($this->_timezone);
}
$result = ($gmt) ? @gmmktime($hour, $minute, $second, $month, $day, $year)
: @mktime($hour, $minute, $second, $month, $day, $year);
date_default_timezone_set($oldzone);
return $result;
}
if ($gmt !== true) {
$second += $this->_offset;
}
if (isset(self::$_cache)) {
$id = strtr('Zend_DateObject_mkTime_' . $this->_offset . '_' . $year.$month.$day.'_'.$hour.$minute.$second . '_'.(int)$gmt, '-','_');
if ($result = self::$_cache->load($id)) {
return unserialize($result);
}
}
// date to integer
$day = intval($day);
$month = intval($month);
$year = intval($year);
// correct months > 12 and months < 1
if ($month > 12) {
$overlap = floor($month / 12);
$year += $overlap;
$month -= $overlap * 12;
} else {
$overlap = ceil((1 - $month) / 12);
$year -= $overlap;
$month += $overlap * 12;
}
$date = 0;
if ($year >= 1970) {
// Date is after UNIX epoch
// go through leapyears
// add months from latest given year
for ($count = 1970; $count <= $year; $count++) {
$leapyear = self::isYearLeapYear($count);
if ($count < $year) {
$date += 365;
if ($leapyear === true) {
$date++;
}
} else {
for ($mcount = 0; $mcount < ($month - 1); $mcount++) {
$date += self::$_monthTable[$mcount];
if (($leapyear === true) and ($mcount == 1)) {
$date++;
}
}
}
}
$date += $day - 1;
$date = (($date * 86400) + ($hour * 3600) + ($minute * 60) + $second);
} else {
// Date is before UNIX epoch
// go through leapyears
// add months from latest given year
for ($count = 1969; $count >= $year; $count--) {
$leapyear = self::isYearLeapYear($count);
if ($count > $year)
{
$date += 365;
if ($leapyear === true)
$date++;
} else {
for ($mcount = 11; $mcount > ($month - 1); $mcount--) {
$date += self::$_monthTable[$mcount];
if (($leapyear === true) and ($mcount == 1)) {
$date++;
}
}
}
}
$date += (self::$_monthTable[$month - 1] - $day);
$date = -(($date * 86400) + (86400 - (($hour * 3600) + ($minute * 60) + $second)));
// gregorian correction for 5.Oct.1582
if ($date < -12220185600) {
$date += 864000;
} else if ($date < -12219321600) {
$date = -12219321600;
}
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($date), $id);
}
return $date;
}
/**
* Returns true, if given $year is a leap year.
*
* @param integer $year
* @return boolean true, if year is leap year
*/
protected static function isYearLeapYear($year)
{
// all leapyears can be divided through 4
if (($year % 4) != 0) {
return false;
}
// all leapyears can be divided through 400
if ($year % 400 == 0) {
return true;
} else if (($year > 1582) and ($year % 100 == 0)) {
return false;
}
return true;
}
/**
* Internal mktime function used by Zend_Date for handling 64bit timestamps.
*
* Returns a formatted date for a given timestamp.
*
* @param string $format format for output
* @param mixed $timestamp
* @param boolean $gmt OPTIONAL true = other arguments are for UTC time, false = arguments are for local time/date
* @return string
*/
protected function date($format, $timestamp = null, $gmt = false)
{
$oldzone = @date_default_timezone_get();
if ($this->_timezone != $oldzone) {
date_default_timezone_set($this->_timezone);
}
if ($timestamp === null) {
$result = ($gmt) ? @gmdate($format) : @date($format);
date_default_timezone_set($oldzone);
return $result;
}
if (abs($timestamp) <= 0x7FFFFFFF) {
$result = ($gmt) ? @gmdate($format, $timestamp) : @date($format, $timestamp);
date_default_timezone_set($oldzone);
return $result;
}
$jump = false;
if (isset(self::$_cache)) {
$idstamp = strtr('Zend_DateObject_date_' . $this->_offset . '_'. $timestamp . '_'.(int)$gmt, '-','_');
if ($result2 = self::$_cache->load($idstamp)) {
$timestamp = unserialize($result2);
$jump = true;
}
}
// check on false or null alone failes
if (empty($gmt) and empty($jump)) {
$tempstamp = $timestamp;
if ($tempstamp > 0) {
while (abs($tempstamp) > 0x7FFFFFFF) {
$tempstamp -= (86400 * 23376);
}
$dst = date("I", $tempstamp);
if ($dst === 1) {
$timestamp += 3600;
}
$temp = date('Z', $tempstamp);
$timestamp += $temp;
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($timestamp), $idstamp);
}
}
if (($timestamp < 0) and ($gmt !== true)) {
$timestamp -= $this->_offset;
}
date_default_timezone_set($oldzone);
$date = $this->getDateParts($timestamp, true);
$length = strlen($format);
$output = '';
for ($i = 0; $i < $length; $i++) {
switch($format[$i]) {
// day formats
case 'd': // day of month, 2 digits, with leading zero, 01 - 31
$output .= (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']);
break;
case 'D': // day of week, 3 letters, Mon - Sun
$output .= date('D', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday'])));
break;
case 'j': // day of month, without leading zero, 1 - 31
$output .= $date['mday'];
break;
case 'l': // day of week, full string name, Sunday - Saturday
$output .= date('l', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday'])));
break;
case 'N': // ISO 8601 numeric day of week, 1 - 7
$day = self::dayOfWeek($date['year'], $date['mon'], $date['mday']);
if ($day == 0) {
$day = 7;
}
$output .= $day;
break;
case 'S': // english suffix for day of month, st nd rd th
if (($date['mday'] % 10) == 1) {
$output .= 'st';
} else if ((($date['mday'] % 10) == 2) and ($date['mday'] != 12)) {
$output .= 'nd';
} else if (($date['mday'] % 10) == 3) {
$output .= 'rd';
} else {
$output .= 'th';
}
break;
case 'w': // numeric day of week, 0 - 6
$output .= self::dayOfWeek($date['year'], $date['mon'], $date['mday']);
break;
case 'z': // day of year, 0 - 365
$output .= $date['yday'];
break;
// week formats
case 'W': // ISO 8601, week number of year
$output .= $this->weekNumber($date['year'], $date['mon'], $date['mday']);
break;
// month formats
case 'F': // string month name, january - december
$output .= date('F', mktime(0, 0, 0, $date['mon'], 2, 1971));
break;
case 'm': // number of month, with leading zeros, 01 - 12
$output .= (($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon']);
break;
case 'M': // 3 letter month name, Jan - Dec
$output .= date('M',mktime(0, 0, 0, $date['mon'], 2, 1971));
break;
case 'n': // number of month, without leading zeros, 1 - 12
$output .= $date['mon'];
break;
case 't': // number of day in month
$output .= self::$_monthTable[$date['mon'] - 1];
break;
// year formats
case 'L': // is leap year ?
$output .= (self::isYearLeapYear($date['year'])) ? '1' : '0';
break;
case 'o': // ISO 8601 year number
$week = $this->weekNumber($date['year'], $date['mon'], $date['mday']);
if (($week > 50) and ($date['mon'] == 1)) {
$output .= ($date['year'] - 1);
} else {
$output .= $date['year'];
}
break;
case 'Y': // year number, 4 digits
$output .= $date['year'];
break;
case 'y': // year number, 2 digits
$output .= substr($date['year'], strlen($date['year']) - 2, 2);
break;
// time formats
case 'a': // lower case am/pm
$output .= (($date['hours'] >= 12) ? 'pm' : 'am');
break;
case 'A': // upper case am/pm
$output .= (($date['hours'] >= 12) ? 'PM' : 'AM');
break;
case 'B': // swatch internet time
$dayseconds = ($date['hours'] * 3600) + ($date['minutes'] * 60) + $date['seconds'];
if ($gmt === true) {
$dayseconds += 3600;
}
$output .= (int) (($dayseconds % 86400) / 86.4);
break;
case 'g': // hours without leading zeros, 12h format
if ($date['hours'] > 12) {
$hour = $date['hours'] - 12;
} else {
if ($date['hours'] == 0) {
$hour = '12';
} else {
$hour = $date['hours'];
}
}
$output .= $hour;
break;
case 'G': // hours without leading zeros, 24h format
$output .= $date['hours'];
break;
case 'h': // hours with leading zeros, 12h format
if ($date['hours'] > 12) {
$hour = $date['hours'] - 12;
} else {
if ($date['hours'] == 0) {
$hour = '12';
} else {
$hour = $date['hours'];
}
}
$output .= (($hour < 10) ? '0'.$hour : $hour);
break;
case 'H': // hours with leading zeros, 24h format
$output .= (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']);
break;
case 'i': // minutes with leading zeros
$output .= (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']);
break;
case 's': // seconds with leading zeros
$output .= (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);
break;
// timezone formats
case 'e': // timezone identifier
if ($gmt === true) {
$output .= gmdate('e', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('e', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'I': // daylight saving time or not
if ($gmt === true) {
$output .= gmdate('I', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('I', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'O': // difference to GMT in hours
$gmtstr = ($gmt === true) ? 0 : $this->_offset;
$output .= sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
break;
case 'P': // difference to GMT with colon
$gmtstr = ($gmt === true) ? 0 : $this->_offset;
$gmtstr = sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
$output = $output . substr($gmtstr, 0, 3) . ':' . substr($gmtstr, 3);
break;
case 'T': // timezone settings
if ($gmt === true) {
$output .= gmdate('T', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
} else {
$output .= date('T', mktime($date['hours'], $date['minutes'], $date['seconds'],
$date['mon'], $date['mday'], 2000));
}
break;
case 'Z': // timezone offset in seconds
$output .= ($gmt === true) ? 0 : -$this->_offset;
break;
// complete time formats
case 'c': // ISO 8601 date format
$difference = $this->_offset;
$difference = sprintf('%s%04d', ($difference <= 0) ? '+' : '-', abs($difference) / 36);
$output .= $date['year'] . '-'
. (($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon']) . '-'
. (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']) . 'T'
. (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']) . ':'
. (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':'
. (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds'])
. $difference;
break;
case 'r': // RFC 2822 date format
$difference = $this->_offset;
$difference = sprintf('%s%04d', ($difference <= 0) ? '+' : '-', abs($difference) / 36);
$output .= gmdate('D', 86400 * (3 + self::dayOfWeek($date['year'], $date['mon'], $date['mday']))) . ', '
. (($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday']) . ' '
. date('M', mktime(0, 0, 0, $date['mon'], 2, 1971)) . ' '
. $date['year'] . ' '
. (($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours']) . ':'
. (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':'
. (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']) . ' '
. $difference;
break;
case 'U': // Unix timestamp
$output .= $timestamp;
break;
// special formats
case "\\": // next letter to print with no format
$i++;
if ($i < $length) {
$output .= $format[$i];
}
break;
default: // letter is no format so add it direct
$output .= $format[$i];
break;
}
}
return (string) $output;
}
/**
* Returns the day of week for a Gregorian calendar date.
* 0 = sunday, 6 = saturday
*
* @param integer $year
* @param integer $month
* @param integer $day
* @return integer dayOfWeek
*/
protected static function dayOfWeek($year, $month, $day)
{
if ((1901 < $year) and ($year < 2038)) {
return (int) date('w', mktime(0, 0, 0, $month, $day, $year));
}
// gregorian correction
$correction = 0;
if (($year < 1582) or (($year == 1582) and (($month < 10) or (($month == 10) && ($day < 15))))) {
$correction = 3;
}
if ($month > 2) {
$month -= 2;
} else {
$month += 10;
$year--;
}
$day = floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4);
$day += floor(($year / 100) / 4) - 2 * floor($year / 100) + 77 + $correction;
return (int) ($day - 7 * floor($day / 7));
}
/**
* Internal getDateParts function for handling 64bit timestamps, similar to:
* http://www.php.net/getdate
*
* Returns an array of date parts for $timestamp, relative to 1970/01/01 00:00:00 GMT/UTC.
*
* $fast specifies ALL date parts should be returned (slower)
* Default is false, and excludes $dayofweek, weekday, month and timestamp from parts returned.
*
* @param mixed $timestamp
* @param boolean $fast OPTIONAL defaults to fast (false), resulting in fewer date parts
* @return array
*/
protected function getDateParts($timestamp = null, $fast = null)
{
// actual timestamp
if ($timestamp === null) {
return getdate();
}
// 32bit timestamp
if (abs($timestamp) <= 0x7FFFFFFF) {
return @getdate($timestamp);
}
if (isset(self::$_cache)) {
$id = strtr('Zend_DateObject_getDateParts_' . $timestamp.'_'.(int)$fast, '-','_');
if ($result = self::$_cache->load($id)) {
return unserialize($result);
}
}
$otimestamp = $timestamp;
$numday = 0;
$month = 0;
// gregorian correction
if ($timestamp < -12219321600) {
$timestamp -= 864000;
}
// timestamp lower 0
if ($timestamp < 0) {
$sec = 0;
$act = 1970;
// iterate through 10 years table, increasing speed
foreach(self::$_yearTable as $year => $seconds) {
if ($timestamp >= $seconds) {
$i = $act;
break;
}
$sec = $seconds;
$act = $year;
}
$timestamp -= $sec;
if (!isset($i)) {
$i = $act;
}
// iterate the max last 10 years
do {
--$i;
$day = $timestamp;
$timestamp += 31536000;
$leapyear = self::isYearLeapYear($i);
if ($leapyear === true) {
$timestamp += 86400;
}
if ($timestamp >= 0) {
$year = $i;
break;
}
} while ($timestamp < 0);
$secondsPerYear = 86400 * ($leapyear ? 366 : 365) + $day;
$timestamp = $day;
// iterate through months
for ($i = 12; --$i >= 0;) {
$day = $timestamp;
$timestamp += self::$_monthTable[$i] * 86400;
if (($leapyear === true) and ($i == 1)) {
$timestamp += 86400;
}
if ($timestamp >= 0) {
$month = $i;
$numday = self::$_monthTable[$i];
if (($leapyear === true) and ($i == 1)) {
++$numday;
}
break;
}
}
$timestamp = $day;
$numberdays = $numday + ceil(($timestamp + 1) / 86400);
$timestamp += ($numday - $numberdays + 1) * 86400;
$hours = floor($timestamp / 3600);
} else {
// iterate through years
for ($i = 1970;;$i++) {
$day = $timestamp;
$timestamp -= 31536000;
$leapyear = self::isYearLeapYear($i);
if ($leapyear === true) {
$timestamp -= 86400;
}
if ($timestamp < 0) {
$year = $i;
break;
}
}
$secondsPerYear = $day;
$timestamp = $day;
// iterate through months
for ($i = 0; $i <= 11; $i++) {
$day = $timestamp;
$timestamp -= self::$_monthTable[$i] * 86400;
if (($leapyear === true) and ($i == 1)) {
$timestamp -= 86400;
}
if ($timestamp < 0) {
$month = $i;
$numday = self::$_monthTable[$i];
if (($leapyear === true) and ($i == 1)) {
++$numday;
}
break;
}
}
$timestamp = $day;
$numberdays = ceil(($timestamp + 1) / 86400);
$timestamp = $timestamp - ($numberdays - 1) * 86400;
$hours = floor($timestamp / 3600);
}
$timestamp -= $hours * 3600;
$month += 1;
$minutes = floor($timestamp / 60);
$seconds = $timestamp - $minutes * 60;
if ($fast === true) {
$array = array(
'seconds' => $seconds,
'minutes' => $minutes,
'hours' => $hours,
'mday' => $numberdays,
'mon' => $month,
'year' => $year,
'yday' => floor($secondsPerYear / 86400),
);
} else {
$dayofweek = self::dayOfWeek($year, $month, $numberdays);
$array = array(
'seconds' => $seconds,
'minutes' => $minutes,
'hours' => $hours,
'mday' => $numberdays,
'wday' => $dayofweek,
'mon' => $month,
'year' => $year,
'yday' => floor($secondsPerYear / 86400),
'weekday' => gmdate('l', 86400 * (3 + $dayofweek)),
'month' => gmdate('F', mktime(0, 0, 0, $month, 1, 1971)),
0 => $otimestamp
);
}
if (isset(self::$_cache)) {
self::$_cache->save( serialize($array), $id);
}
return $array;
}
/**
* Internal getWeekNumber function for handling 64bit timestamps
*
* Returns the ISO 8601 week number of a given date
*
* @param integer $year
* @param integer $month
* @param integer $day
* @return integer
*/
protected function weekNumber($year, $month, $day)
{
if ((1901 < $year) and ($year < 2038)) {
return (int) date('W', mktime(0, 0, 0, $month, $day, $year));
}
$dayofweek = self::dayOfWeek($year, $month, $day);
$firstday = self::dayOfWeek($year, 1, 1);
if (($month == 1) and (($firstday < 1) or ($firstday > 4)) and ($day < 4)) {
$firstday = self::dayOfWeek($year - 1, 1, 1);
$month = 12;
$day = 31;
} else if (($month == 12) and ((self::dayOfWeek($year + 1, 1, 1) < 5) and
(self::dayOfWeek($year + 1, 1, 1) > 0))) {
return 1;
}
return intval (((self::dayOfWeek($year, 1, 1) < 5) and (self::dayOfWeek($year, 1, 1) > 0)) +
4 * ($month - 1) + (2 * ($month - 1) + ($day - 1) + $firstday - $dayofweek + 6) * 36 / 256);
}
/**
* Internal _range function
* Sets the value $a to be in the range of [0, $b]
*
* @param float $a - value to correct
* @param float $b - maximum range to set
*/
private function _range($a, $b) {
while ($a < 0) {
$a += $b;
}
while ($a >= $b) {
$a -= $b;
}
return $a;
}
/**
* 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 + 3.49066E-4 * 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.91746 * $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);
}
/**
* Sets a new timezone for calculation of $this object's gmt offset.
* For a list of supported timezones look here: http://php.net/timezones
* If no timezone can be detected or the given timezone is wrong UTC will be set.
*
* @param string $zone OPTIONAL timezone for date calculation; defaults to date_default_timezone_get()
* @return Zend_Date_DateObject Provides fluent interface
* @throws Zend_Date_Exception
*/
public function setTimezone($zone = null)
{
$oldzone = @date_default_timezone_get();
if ($zone === null) {
$zone = $oldzone;
}
// throw an error on false input, but only if the new date extension is available
if (function_exists('timezone_open')) {
if (!@timezone_open($zone)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("timezone ($zone) is not a known timezone", $zone);
}
}
// this can generate an error if the date extension is not available and a false timezone is given
$result = @date_default_timezone_set($zone);
if ($result === true) {
$this->_offset = mktime(0, 0, 0, 1, 2, 1970) - gmmktime(0, 0, 0, 1, 2, 1970);
$this->_timezone = $zone;
}
date_default_timezone_set($oldzone);
if (($zone == 'UTC') or ($zone == 'GMT')) {
$this->_dst = false;
} else {
$this->_dst = true;
}
return $this;
}
/**
* Return the timezone of $this object.
* The timezone is initially set when the object is instantiated.
*
* @return string actual set timezone string
*/
public function getTimezone()
{
return $this->_timezone;
}
/**
* Return the offset to GMT of $this object's timezone.
* The offset to GMT is initially set when the object is instantiated using the currently,
* in effect, default timezone for PHP functions.
*
* @return integer seconds difference between GMT timezone and timezone when object was instantiated
*/
public function getGmtOffset()
{
return $this->_offset;
}
}
Exception.php 0000604 00000002456 15071442100 0007210 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Date_Exception extends Zend_Exception
{
protected $operand = null;
public function __construct($message, $op = null)
{
$this->operand = $op;
parent::__construct($message);
}
public function getOperand()
{
return $this->operand;
}
}
Cities.php 0000604 00000056357 15071442100 0006503 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DateObject.php 2511 2006-12-26 22:54:37Z bkarwin $
*/
/**
* Additional data for sunset/sunrise calculations
*
* Holds the geographical data for all capital cities and many others worldwide
* Original data from http://www.fallingrain.com/world/
*
* @category Zend
* @package Zend_Date
* @subpackage Zend_Date_Cities
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Date_Cities
{
/**
* Array Collection of known cities
*
* The array contains 'latitude' and 'longitude' for every known city
*
* @var Array
*/
public static $cities = array(
'Abidjan' => array('latitude' => 5.3411111, 'longitude' => -4.0280556),
'Abu Dhabi' => array('latitude' => 24.4666667, 'longitude' => 54.3666667),
'Abuja' => array('latitude' => 9.1758333, 'longitude' => 7.1808333),
'Accra' => array('latitude' => 5.55, 'longitude' => -0.2166667),
'Adamstown' => array('latitude' => -25.0666667, 'longitude' => -130.0833333),
'Addis Ababa' => array('latitude' => 9.0333333, 'longitude' => 38.7),
'Adelaide' => array('latitude' => -34.9333333, 'longitude' => 138.6),
'Algiers' => array('latitude' => 36.7630556, 'longitude' => 3.0505556),
'Alofi' => array('latitude' => -19.0166667, 'longitude' => -169.9166667),
'Amman' => array('latitude' => 31.95, 'longitude' => 35.9333333),
'Amsterdam' => array('latitude' => 52.35, 'longitude' => 4.9166667),
'Andorra la Vella' => array('latitude' => 42.5, 'longitude' => 1.5166667),
'Ankara' => array('latitude' => 39.9272222, 'longitude' => 32.8644444),
'Antananarivo' => array('latitude' => -18.9166667, 'longitude' => 47.5166667),
'Apia' => array('latitude' => -13.8333333, 'longitude' => -171.7333333),
'Ashgabat' => array('latitude' => 37.95, 'longitude' => 58.3833333),
'Asmara' => array('latitude' => 15.3333333, 'longitude' => 38.9333333),
'Astana' => array('latitude' => 51.1811111, 'longitude' => 71.4277778),
'Asunción' => array('latitude' => -25.2666667, 'longitude' => -57.6666667),
'Athens' => array('latitude' => 37.9833333, 'longitude' => 23.7333333),
'Auckland' => array('latitude' => -36.8666667, 'longitude' => 174.7666667),
'Avarua' => array('latitude' => -21.2, 'longitude' => -159.7666667),
'Baghdad' => array('latitude' => 33.3386111, 'longitude' => 44.3938889),
'Baku' => array('latitude' => 40.3952778, 'longitude' => 49.8822222),
'Bamako' => array('latitude' => 12.65, 'longitude' => -8),
'Bandar Seri Begawan' => array('latitude' => 4.8833333, 'longitude' => 114.9333333),
'Bankok' => array('latitude' => 13.5833333, 'longitude' => 100.2166667),
'Bangui' => array('latitude' => 4.3666667, 'longitude' => 18.5833333),
'Banjul' => array('latitude' => 13.4530556, 'longitude' => -16.5775),
'Basel' => array('latitude' => 47.5666667, 'longitude' => 7.6),
'Basseterre' => array('latitude' => 17.3, 'longitude' => -62.7166667),
'Beijing' => array('latitude' => 39.9288889, 'longitude' => 116.3883333),
'Beirut' => array('latitude' => 33.8719444, 'longitude' => 35.5097222),
'Belgrade' => array('latitude' => 44.8186111, 'longitude' => 20.4680556),
'Belmopan' => array('latitude' => 17.25, 'longitude' => -88.7666667),
'Berlin' => array('latitude' => 52.5166667, 'longitude' => 13.4),
'Bern' => array('latitude' => 46.9166667, 'longitude' => 7.4666667),
'Bishkek' => array('latitude' => 42.8730556, 'longitude' => 74.6002778),
'Bissau' => array('latitude' => 11.85, 'longitude' => -15.5833333),
'Bloemfontein' => array('latitude' => -29.1333333, 'longitude' => 26.2),
'Bogotá' => array('latitude' => 4.6, 'longitude' => -74.0833333),
'Brasilia' => array('latitude' => -15.7833333, 'longitude' => -47.9166667),
'Bratislava' => array('latitude' => 48.15, 'longitude' => 17.1166667),
'Brazzaville' => array('latitude' => -4.2591667, 'longitude' => 15.2847222),
'Bridgetown' => array('latitude' => 13.1, 'longitude' => -59.6166667),
'Brisbane' => array('latitude' => -27.5, 'longitude' => 153.0166667),
'Brussels' => array('latitude' => 50.8333333, 'longitude' => 4.3333333),
'Bucharest' => array('latitude' => 44.4333333, 'longitude' => 26.1),
'Budapest' => array('latitude' => 47.5, 'longitude' => 19.0833333),
'Buenos Aires' => array('latitude' => -34.5875, 'longitude' => -58.6725),
'Bujumbura' => array('latitude' => -3.3761111, 'longitude' => 29.36),
'Cairo' => array('latitude' => 30.05, 'longitude' => 31.25),
'Calgary' => array('latitude' => 51.0833333, 'longitude' => -114.0833333),
'Canberra' => array('latitude' => -35.2833333, 'longitude' => 149.2166667),
'Cape Town' => array('latitude' => -33.9166667, 'longitude' => 18.4166667),
'Caracas' => array('latitude' => 10.5, 'longitude' => -66.9166667),
'Castries' => array('latitude' => 14, 'longitude' => -61),
'Charlotte Amalie' => array('latitude' => 18.34389, 'longitude' => -64.93111),
'Chicago' => array('latitude' => 41.85, 'longitude' => -87.65),
'Chisinau' => array('latitude' => 47.055556, 'longitude' => 28.8575),
'Cockburn Town' => array('latitude' => 21.4666667, 'longitude' => -71.1333333),
'Colombo' => array('latitude' => 6.9319444, 'longitude' => 79.8477778),
'Conakry' => array('latitude' => 9.5091667, 'longitude' => -13.7122222),
'Copenhagen' => array('latitude' => 55.6666667, 'longitude' => 12.5833333),
'Cotonou' => array('latitude' => 6.35, 'longitude' => 2.4333333),
'Dakar' => array('latitude' => 14.6708333, 'longitude' => -17.4380556),
'Damascus' => array('latitude' => 33.5, 'longitude' => 36.3),
'Dar es Salaam' => array('latitude' => -6.8, 'longitude' => 39.2833333),
'Dhaka' => array('latitude' => 23.7230556, 'longitude' => 90.4086111),
'Dili' => array('latitude' => -8.5586111, 'longitude' => 125.5736111),
'Djibouti' => array('latitude' => 11.595, 'longitude' => 43.1480556),
'Dodoma' => array('latitude' => -6.1833333, 'longitude' => 35.75),
'Doha' => array('latitude' => 25.2866667, 'longitude' => 51.5333333),
'Dubai' => array('latitude' => 25.2522222, 'longitude' => 55.28),
'Dublin' => array('latitude' => 53.3330556, 'longitude' => -6.2488889),
'Dushanbe' => array('latitude' => 38.56, 'longitude' => 68.7738889 ),
'Fagatogo' => array('latitude' => -14.2825, 'longitude' => -170.69),
'Fongafale' => array('latitude' => -8.5166667, 'longitude' => 179.2166667),
'Freetown' => array('latitude' => 8.49, 'longitude' => -13.2341667),
'Gaborone' => array('latitude' => -24.6463889, 'longitude' => 25.9119444),
'Geneva' => array('latitude' => 46.2, 'longitude' => 6.1666667),
'George Town' => array('latitude' => 19.3, 'longitude' => -81.3833333),
'Georgetown' => array('latitude' => 6.8, 'longitude' => -58.1666667),
'Gibraltar' => array('latitude' => 36.1333333, 'longitude' => -5.35),
'Glasgow' => array('latitude' => 55.8333333, 'longitude' => -4.25),
'Guatemala la Nueva' => array('latitude' => 14.6211111, 'longitude' => -90.5269444),
'Hagatna' => array('latitude' => 13.47417, 'longitude' => 144.74778),
'The Hague' => array('latitude' => 52.0833333, 'longitude' => 4.3),
'Hamilton' => array('latitude' => 32.2941667, 'longitude' => -64.7838889),
'Hanoi' => array('latitude' => 21.0333333, 'longitude' => 105.85),
'Harare' => array('latitude' => -17.8177778, 'longitude' => 31.0447222),
'Havana' => array('latitude' => 23.1319444, 'longitude' => -82.3641667),
'Helsinki' => array('latitude' => 60.1755556, 'longitude' => 24.9341667),
'Honiara' => array('latitude' => -9.4333333, 'longitude' => 159.95),
'Islamabad' => array('latitude' => 30.8486111, 'longitude' => 72.4944444),
'Istanbul' => array('latitude' => 41.0186111, 'longitude' => 28.9647222),
'Jakarta' => array('latitude' => -6.1744444, 'longitude' => 106.8294444),
'Jamestown' => array('latitude' => -15.9333333, 'longitude' => -5.7166667),
'Jerusalem' => array('latitude' => 31.7666667, 'longitude' => 35.2333333),
'Johannesburg' => array('latitude' => -26.2, 'longitude' => 28.0833333),
'Kabul' => array('latitude' => 34.5166667, 'longitude' => 69.1833333),
'Kampala' => array('latitude' => 0.3155556, 'longitude' => 32.5655556),
'Kathmandu' => array('latitude' => 27.7166667, 'longitude' => 85.3166667),
'Khartoum' => array('latitude' => 15.5880556, 'longitude' => 32.5341667),
'Kigali' => array('latitude' => -1.9536111, 'longitude' => 30.0605556),
'Kingston' => array('latitude' => -29.05, 'longitude' => 167.95),
'Kingstown' => array('latitude' => 13.1333333, 'longitude' => -61.2166667),
'Kinshasa' => array('latitude' => -4.3, 'longitude' => 15.3),
'Kolkata' => array('latitude' => 22.5697222, 'longitude' => 88.3697222),
'Kuala Lumpur' => array('latitude' => 3.1666667, 'longitude' => 101.7),
'Kuwait City' => array('latitude' => 29.3697222, 'longitude' => 47.9783333),
'Kiev' => array('latitude' => 50.4333333, 'longitude' => 30.5166667),
'La Paz' => array('latitude' => -16.5, 'longitude' => -68.15),
'Libreville' => array('latitude' => 0.3833333, 'longitude' => 9.45),
'Lilongwe' => array('latitude' => -13.9833333, 'longitude' => 33.7833333),
'Lima' => array('latitude' => -12.05, 'longitude' => -77.05),
'Lisbon' => array('latitude' => 38.7166667, 'longitude' => -9.1333333),
'Ljubljana' => array('latitude' => 46.0552778, 'longitude' => 14.5144444),
'Lobamba' => array('latitude' => -26.4666667, 'longitude' => 31.2),
'Lomé' => array('latitude' => 9.7166667, 'longitude' => 38.3),
'London' => array('latitude' => 51.5, 'longitude' => -0.1166667),
'Los Angeles' => array('latitude' => 34.05222, 'longitude' => -118.24278),
'Luanda' => array('latitude' => -8.8383333, 'longitude' => 13.2344444),
'Lusaka' => array('latitude' => -15.4166667, 'longitude' => 28.2833333),
'Luxembourg' => array('latitude' => 49.6116667, 'longitude' => 6.13),
'Madrid' => array('latitude' => 40.4, 'longitude' => -3.6833333),
'Majuro' => array('latitude' => 7.1, 'longitude' => 171.3833333),
'Malabo' => array('latitude' => 3.75, 'longitude' => 8.7833333),
'Managua' => array('latitude' => 12.1508333, 'longitude' => -86.2683333),
'Manama' => array('latitude' => 26.2361111, 'longitude' => 50.5830556),
'Manila' => array('latitude' => 14.6041667, 'longitude' => 120.9822222),
'Maputo' => array('latitude' => -25.9652778, 'longitude' => 32.5891667),
'Maseru' => array('latitude' => -29.3166667, 'longitude' => 27.4833333),
'Mbabane' => array('latitude' => -26.3166667, 'longitude' => 31.1333333),
'Melbourne' => array('latitude' => -37.8166667, 'longitude' => 144.9666667),
'Melekeok' => array('latitude' => 7.4933333, 'longitude' => 134.6341667),
'Mexiko City' => array('latitude' => 19.4341667, 'longitude' => -99.1386111),
'Minsk' => array('latitude' => 53.9, 'longitude' => 27.5666667),
'Mogadishu' => array('latitude' => 2.0666667, 'longitude' => 45.3666667),
'Monaco' => array('latitude' => 43.7333333, 'longitude' => 7.4166667),
'Monrovia' => array('latitude' => 6.3105556, 'longitude' => -10.8047222),
'Montevideo' => array('latitude' => -34.8580556, 'longitude' => -56.1708333),
'Montreal' => array('latitude' => 45.5, 'longitude' => -73.5833333),
'Moroni' => array('latitude' => -11.7041667, 'longitude' => 43.2402778),
'Moscow' => array('latitude' => 55.7522222, 'longitude' => 37.6155556),
'Muscat' => array('latitude' => 23.6133333, 'longitude' => 58.5933333),
'Nairobi' => array('latitude' => -1.3166667, 'longitude' => 36.8333333),
'Nassau' => array('latitude' => 25.0833333, 'longitude' => -77.35),
'N´Djamena' => array('latitude' => 12.1130556, 'longitude' => 15.0491667),
'New Dehli' => array('latitude' => 28.6, 'longitude' => 77.2),
'New York' => array('latitude' => 40.71417, 'longitude' => -74.00639),
'Newcastle' => array('latitude' => -32.9166667, 'longitude' => 151.75),
'Niamey' => array('latitude' => 13.6666667, 'longitude' => 1.7833333),
'Nicosia' => array('latitude' => 35.1666667, 'longitude' => 33.3666667),
'Nouakchott' => array('latitude' => 18.0863889, 'longitude' => -15.9752778),
'Noumea' => array('latitude' => -22.2666667, 'longitude' => 166.45),
'Nuku´alofa' => array('latitude' => -21.1333333, 'longitude' => -175.2),
'Nuuk' => array('latitude' => 64.1833333, 'longitude' => -51.75),
'Oranjestad' => array('latitude' => 12.5166667, 'longitude' => -70.0333333),
'Oslo' => array('latitude' => 59.9166667, 'longitude' => 10.75),
'Ouagadougou' => array('latitude' => 12.3702778, 'longitude' => -1.5247222),
'Palikir' => array('latitude' => 6.9166667, 'longitude' => 158.15),
'Panama City' => array('latitude' => 8.9666667, 'longitude' => -79.5333333),
'Papeete' => array('latitude' => -17.5333333, 'longitude' => -149.5666667),
'Paramaribo' => array('latitude' => 5.8333333, 'longitude' => -55.1666667),
'Paris' => array('latitude' => 48.8666667, 'longitude' => 2.3333333),
'Perth' => array('latitude' => -31.9333333, 'longitude' => 115.8333333),
'Phnom Penh' => array('latitude' => 11.55, 'longitude' => 104.9166667),
'Podgorica' => array('latitude' => 43.7752778, 'longitude' => 19.6827778),
'Port Louis' => array('latitude' => -20.1666667, 'longitude' => 57.5),
'Port Moresby' => array('latitude' => -9.4647222, 'longitude' => 147.1925),
'Port-au-Prince' => array('latitude' => 18.5391667, 'longitude' => -72.335),
'Port of Spain' => array('latitude' => 10.6666667, 'longitude' => -61.5),
'Porto-Novo' => array('latitude' => 6.4833333, 'longitude' => 2.6166667),
'Prague' => array('latitude' => 50.0833333, 'longitude' => 14.4666667),
'Praia' => array('latitude' => 14.9166667, 'longitude' => -23.5166667),
'Pretoria' => array('latitude' => -25.7069444, 'longitude' => 28.2294444),
'Pyongyang' => array('latitude' => 39.0194444, 'longitude' => 125.7547222),
'Quito' => array('latitude' => -0.2166667, 'longitude' => -78.5),
'Rabat' => array('latitude' => 34.0252778, 'longitude' => -6.8361111),
'Reykjavik' => array('latitude' => 64.15, 'longitude' => -21.95),
'Riga' => array('latitude' => 56.95, 'longitude' => 24.1),
'Rio de Janero' => array('latitude' => -22.9, 'longitude' => -43.2333333),
'Road Town' => array('latitude' => 18.4166667, 'longitude' => -64.6166667),
'Rome' => array('latitude' => 41.9, 'longitude' => 12.4833333),
'Roseau' => array('latitude' => 15.3, 'longitude' => -61.4),
'Rotterdam' => array('latitude' => 51.9166667, 'longitude' => 4.5),
'Salvador' => array('latitude' => -12.9833333, 'longitude' => -38.5166667),
'San José' => array('latitude' => 9.9333333, 'longitude' => -84.0833333),
'San Juan' => array('latitude' => 18.46833, 'longitude' => -66.10611),
'San Marino' => array('latitude' => 43.5333333, 'longitude' => 12.9666667),
'San Salvador' => array('latitude' => 13.7086111, 'longitude' => -89.2030556),
'Sanaá' => array('latitude' => 15.3547222, 'longitude' => 44.2066667),
'Santa Cruz' => array('latitude' => -17.8, 'longitude' => -63.1666667),
'Santiago' => array('latitude' => -33.45, 'longitude' => -70.6666667),
'Santo Domingo' => array('latitude' => 18.4666667, 'longitude' => -69.9),
'Sao Paulo' => array('latitude' => -23.5333333, 'longitude' => -46.6166667),
'Sarajevo' => array('latitude' => 43.85, 'longitude' => 18.3833333),
'Seoul' => array('latitude' => 37.5663889, 'longitude' => 126.9997222),
'Shanghai' => array('latitude' => 31.2222222, 'longitude' => 121.4580556),
'Sydney' => array('latitude' => -33.8833333, 'longitude' => 151.2166667),
'Singapore' => array('latitude' => 1.2930556, 'longitude' => 103.8558333),
'Skopje' => array('latitude' => 42, 'longitude' => 21.4333333),
'Sofia' => array('latitude' => 42.6833333, 'longitude' => 23.3166667),
'St. George´s' => array('latitude' => 12.05, 'longitude' => -61.75),
'St. John´s' => array('latitude' => 17.1166667, 'longitude' => -61.85),
'Stanley' => array('latitude' => -51.7, 'longitude' => -57.85),
'Stockholm' => array('latitude' => 59.3333333, 'longitude' => 18.05),
'Suva' => array('latitude' => -18.1333333, 'longitude' => 178.4166667),
'Taipei' => array('latitude' => 25.0166667, 'longitude' => 121.45),
'Tallinn' => array('latitude' => 59.4338889, 'longitude' => 24.7280556),
'Tashkent' => array('latitude' => 41.3166667, 'longitude' => 69.25),
'Tbilisi' => array('latitude' => 41.725, 'longitude' => 44.7908333),
'Tegucigalpa' => array('latitude' => 14.1, 'longitude' => -87.2166667),
'Tehran' => array('latitude' => 35.6719444, 'longitude' => 51.4244444),
'The Hague' => array('latitude' => 52.0833333, 'longitude' => 4.3),
'Thimphu' => array('latitude' => 27.4833333, 'longitude' => 89.6),
'Tirana' => array('latitude' => 41.3275, 'longitude' => 19.8188889),
'Tiraspol' => array('latitude' => 46.8402778, 'longitude' => 29.6433333),
'Tokyo' => array('latitude' => 35.685, 'longitude' => 139.7513889),
'Toronto' => array('latitude' => 43.6666667, 'longitude' => -79.4166667),
'Tórshavn' => array('latitude' => 62.0166667, 'longitude' => -6.7666667),
'Tripoli' => array('latitude' => 32.8925, 'longitude' => 13.18),
'Tunis' => array('latitude' => 36.8027778, 'longitude' => 10.1797222),
'Ulaanbaatar' => array('latitude' => 47.9166667, 'longitude' => 106.9166667),
'Vaduz' => array('latitude' => 47.1333333, 'longitude' => 9.5166667),
'Valletta' => array('latitude' => 35.8997222, 'longitude' => 14.5147222),
'Valparaiso' => array('latitude' => -33.0477778, 'longitude' => -71.6011111),
'Vancouver' => array('latitude' => 49.25, 'longitude' => -123.1333333),
'Vatican City' => array('latitude' => 41.9, 'longitude' => 12.4833333),
'Victoria' => array('latitude' => -4.6166667, 'longitude' => 55.45),
'Vienna' => array('latitude' => 48.2, 'longitude' => 16.3666667),
'Vientaine' => array('latitude' => 17.9666667, 'longitude' => 102.6),
'Vilnius' => array('latitude' => 54.6833333, 'longitude' => 25.3166667),
'Warsaw' => array('latitude' => 52.25, 'longitude' => 21),
'Washington dc' => array('latitude' => 38.895, 'longitude' => -77.03667),
'Wellington' => array('latitude' => -41.3, 'longitude' => 174.7833333),
'Willemstad' => array('latitude' => 12.1, 'longitude' => -68.9166667),
'Windhoek' => array('latitude' => -22.57, 'longitude' => 17.0836111),
'Yamoussoukro' => array('latitude' => 6.8166667, 'longitude' => -5.2833333),
'Yaoundé' => array('latitude' => 3.8666667, 'longitude' => 11.5166667),
'Yerevan' => array('latitude' => 40.1811111, 'longitude' => 44.5136111),
'Zürich' => array('latitude' => 47.3666667, 'longitude' => 8.55),
'Zagreb' => array('latitude' => 45.8, 'longitude' => 16)
);
/**
* Returns the location from the selected city
*
* @param string $city City to get location for
* @param string $horizon Horizon to use :
* default: effective
* others are civil, nautic, astronomic
* @return array
* @throws Zend_Date_Exception When city is unknown
*/
public static function City($city, $horizon = false)
{
foreach (self::$cities as $key => $value) {
if (strtolower($key) === strtolower($city)) {
$return = $value;
$return['horizon'] = $horizon;
return $return;
}
}
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('unknown city');
}
/**
* Return a list with all known cities
*
* @return array
*/
public static function getCityList()
{
return array_keys(self::$cities);
}
}