Changeset 527331
- Timestamp:
- 04/04/2012 01:48:29 PM (14 years ago)
- Location:
- sunrise-sunset/trunk
- Files:
-
- 1 added
- 3 edited
-
functions.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
sunrisesunset.php (modified) (6 diffs)
-
utils.php (added)
Legend:
- Unmodified
- Added
- Removed
-
sunrise-sunset/trunk/functions.php
r527059 r527331 2 2 3 3 4 5 -
sunrise-sunset/trunk/readme.txt
r527116 r527331 7 7 License: GPLv2 8 8 9 Displays sunrise and sunset times for the capital cities of theAmerica (including miscellaneous cities).10 Times displayed are local time.9 Displays sunrise and sunset times for the capital cities in America (including miscellaneous cities). 10 Local times are displayed. 11 11 12 12 == Description == -
sunrise-sunset/trunk/sunrisesunset.php
r527113 r527331 27 27 28 28 require_once "city.php"; 29 require_once " functions.php";29 require_once "utils.php"; 30 30 31 31 add_action("widgets_init", "register_sunrise_sunset"); … … 39 39 private $_cities; 40 40 41 private function populateCities()42 {43 $lines = file(dirname(__FILE__) . '/cities.txt');44 foreach ($lines as $line) {45 $pieces = explode(":", $line);46 if ($pieces[0] == 'city') continue;47 $this->_cities[$pieces[0]] = new City($pieces[0], $pieces[1], $pieces[2], $pieces[3], $pieces[4]);48 }49 }50 51 52 41 function sunrise_sunset() 53 42 { … … 57 46 $this->WP_Widget('ss_widget_bio', 'Sunrise Sunset', $widget_ops); 58 47 59 $this-> populateCities();48 $this->_cities = SSUtils::getCities(); 60 49 } 61 50 … … 118 107 <p> 119 108 <br/> 120 121 109 </p> 122 110 <?php … … 149 137 } 150 138 151 152 $result = $this->ss_get_times($instance); 139 $result = SSUtils::getTimes($instance, $this->_cities); 153 140 154 141 echo $today . "<br/>"; … … 163 150 echo $after_widget; 164 151 } 165 166 private function convertTimezone($timestamp, $city)167 {168 $newTimestamp = 0;169 $time_format = 'Y-m-d';170 $currentTimezone = $city->getTimezone();171 172 $dstStart = '2012-03-11';173 $dstEnd = '2012-11-04';174 $today = date($time_format, $timestamp);175 176 if ((($today >= $dstStart) && ($today <= $dstEnd))) {177 $currentTimezone = $city->getSummerTimezone();178 }179 180 switch ($currentTimezone) {181 case 'EST':182 $newTimestamp = $timestamp - (5 * 60 * 60);183 break;184 case 'EDT':185 $newTimestamp = $timestamp - (4 * 60 * 60);186 break;187 case 'MST':188 $newTimestamp = $timestamp - (7 * 60 * 60);189 break;190 case 'MDT':191 $newTimestamp = $timestamp - (6 * 60 * 60);192 break;193 case 'CST':194 $newTimestamp = $timestamp - (6 * 60 * 60);195 break;196 case 'CDT':197 $newTimestamp = $timestamp - (5 * 60 * 60);198 break;199 case 'PST':200 $newTimestamp = $timestamp - (8 * 60 * 60);201 break;202 case 'PDT':203 $newTimestamp = $timestamp - (7 * 60 * 60);204 break;205 case 'AKST':206 $newTimestamp = $timestamp - (9 * 60 * 60);207 break;208 case 'AKDT':209 $newTimestamp = $timestamp - (8 * 60 * 60);210 break;211 case 'HAST':212 $newTimestamp = $timestamp - (10 * 60 * 60);213 break;214 }215 216 217 return $newTimestamp;218 }219 220 221 function ss_get_times($instance)222 {223 $time_format = 'h:i A';224 $targetCity = $this->_cities[$instance['city']];225 226 $lat = $targetCity->getLatitude();227 $long = $targetCity->getLongitude();228 229 $suninfo = date_sun_info(time(), $lat, $long);230 231 $sunrise_time = date($time_format, $this->convertTimezone($suninfo['sunrise'], $targetCity));232 $sunset_time = date($time_format, $this->convertTimezone($suninfo['sunset'], $targetCity));233 234 return array('sunrise' => $sunrise_time, 'sunset' => $sunset_time);235 }236 152 } 237 153
Note: See TracChangeset
for help on using the changeset viewer.