function all() { $timezones = AkTimeZone::getTimeZoneDescriptions(); $timezone_array = array(); $i = 0; foreach ($timezones as $timezone) { $timezone_pieces = explode('|', $timezone); $timezone_array[$timezone_pieces[1]] = $timezone_pieces[0]; } return $timezone_array; }
public function test_should_be_sorted() { $Zones =& AkTimeZone::all(); foreach (range(1,count($Zones)-1) as $i){ $this->assertTrue($Zones[$i-1]->compare($Zones[$i]) == -1); } }
/** * Returns a string of option tags for pretty much any time zone in the * world. Supply a TimeZone name as +selected+ to have it marked as the * selected option tag. You can also supply an array of TimeZones * as +$priority_zones+, so that they will be listed above the rest of the * (long) list. * * The +selected+ parameter must be either +null+, or a string that names * a TimeZone. * * By default, +model+ is the AkTimeZone constant (which can be obtained * in ActiveRecord as a value object). The only requirement is that the * +model+ parameter be an object that responds to #all, and returns * an array with the Time zone description as key and the GTM time difference as values. * * NOTE: Only the option tags are returned, you have to wrap this call in * a regular HTML select tag. */ function time_zone_options_for_select($selected = null, $priority_zones = array(), $model = 'AkTimeZone') { $zone_options = ''; if ($model == 'AkTimeZone') { require_once AK_LIB_DIR . DS . 'AkLocalize' . DS . 'AkTimeZone.php'; $zones_form_method = AkTimeZone::all(); } else { $zones_form_method = $model->all(); } $zones = array(); foreach ($zones_form_method as $description => $gmt) { $k = Ak::t('(%gmt) %description', array('%gmt' => $gmt, '%description' => $description), 'localize/timezones'); //$timezone = ltrim(str_replace(array('GMT',':00',':30',' ','+0','-0','+'),array('','','.5','','','-',''),$gmt),'()'); $zones[$k] = $description; } if (!empty($priority_zones)) { $zone_options .= $this->options_for_select($priority_zones, $selected); $zone_options .= '<option value="">-------------</option>' . "\n"; } $zone_options .= $this->options_for_select(array_diff($zones, $priority_zones), $selected); return $zone_options; }
/** * Return an array of all AkTimeZone objects. There are multiple AkTimeZone objects * per time zone, in many cases, to make it easier for users to find their own time zone. */ function &all() { $TimeZone = new AkTimeZone(); $time_zones = $TimeZone->getTimezones(); $dst_zones = $TimeZone->dst_zones; $Zones = array(); foreach ($time_zones as $name => $offset) { $Zones[] = $TimeZone->create($name, $offset, $time_zones, $dst_zones); } return $Zones; }
/** * Returns a string of option tags for pretty much any time zone in the * world. Supply a TimeZone name as +selected+ to have it marked as the * selected option tag. You can also supply an array of TimeZones * as +$priority_zones+, so that they will be listed above the rest of the * (long) list. * * The +selected+ parameter must be either +null+, or a string that names * a TimeZone. * * By default, +model+ is an AkTimeZone instance. The only requirement is that the * +model+ parameter be an object that responds to #all, and returns * an object with a toString() method and the TimeZone name provided by a 'name' * attribute * * For a list of supported timezones see: http://www.php.net/manual/en/timezones.php * * NOTE: Only the option tags are returned, you have to wrap this call in * a regular HTML select tag. */ function time_zone_options_for_select($selected = null, $priority_zones = array(), $model = 'AkTimeZone') { $zone_options = ''; if($model == 'AkTimeZone'){ require_once(AK_LIB_DIR.DS.'AkLocalize'.DS.'AkTimeZone.php'); $Zones = AkTimeZone::all(); }else{ $Zones = $model->all(); } $zones_for_options = array(); foreach (array_keys($Zones) as $k){ $zones_for_options[$Zones[$k]->toString()] = $Zones[$k]->name; } if (!empty($priority_zones)){ $zone_options .= $this->options_for_select($priority_zones, $selected); $zone_options .= '<option value="">-------------</option>'."\n"; } $zone_options .= $this->options_for_select(array_diff_assoc($zones_for_options,$priority_zones), $selected); return $zone_options; }