Plugin Directory

Changeset 527331


Ignore:
Timestamp:
04/04/2012 01:48:29 PM (14 years ago)
Author:
rxn
Message:

Added Timezone in display. Refactored Code

Location:
sunrise-sunset/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • sunrise-sunset/trunk/functions.php

    r527059 r527331  
    22
    33
     4
     5
  • sunrise-sunset/trunk/readme.txt

    r527116 r527331  
    77License: GPLv2
    88
    9 Displays sunrise and sunset times for the capital cities of the America (including miscellaneous cities).
    10 Times displayed are local time.
     9Displays sunrise and sunset times for the capital cities in America (including miscellaneous cities).
     10Local times are displayed.
    1111
    1212== Description ==
  • sunrise-sunset/trunk/sunrisesunset.php

    r527113 r527331  
    2727
    2828require_once "city.php";
    29 require_once "functions.php";
     29require_once "utils.php";
    3030
    3131add_action("widgets_init", "register_sunrise_sunset");
     
    3939    private $_cities;
    4040
    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 
    5241    function sunrise_sunset()
    5342    {
     
    5746        $this->WP_Widget('ss_widget_bio', 'Sunrise Sunset', $widget_ops);
    5847
    59         $this->populateCities();
     48        $this->_cities = SSUtils::getCities();
    6049    }
    6150
     
    118107    <p>
    119108        <br/>
    120 
    121109    </p>
    122110    <?php
     
    149137        }
    150138
    151 
    152         $result = $this->ss_get_times($instance);
     139        $result = SSUtils::getTimes($instance, $this->_cities);
    153140
    154141        echo $today . "<br/>";
     
    163150        echo $after_widget;
    164151    }
    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     }
    236152}
    237153
Note: See TracChangeset for help on using the changeset viewer.