Skip to content

Commit

Permalink
Merge pull request #1 from richgoldmd/master
Browse files Browse the repository at this point in the history
FIxed some undefined vars and also a syntactical error in refering to…
  • Loading branch information
Scott Connerly authored Mar 27, 2018
2 parents bc4314f + 8ca0b13 commit f3cfa40
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/TimeZoneSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static function get_select_html($params = []) {
}

public static function get_options_for_select($params = []) {
$output = '';
$priorityData = [];

if (!empty($params['country'])) {
$params['priority_zones'] = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $params['country']);
//$params['priority_label'] = locale_get_display_region('-'.$params['country'], 'en');
Expand Down Expand Up @@ -79,13 +82,15 @@ protected static function make_zone_option($tzDatum, $params = []) {
}

public static function get_time_zones($params = []) {
// Prep varrs and arrays that wil lbe accessed but not yet created
$identifiers = array();
$tzData = [];
$tzJson = file_get_contents(__DIR__."/../tzid.json");
$tzs = json_decode($tzJson);

$defaultTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC'); //Is this problematic for larger systems to load this file? Should we return it to its value?
$i = 0;
foreach($tzs as $nameDisplay => $tzinfoIdentifier) {
$offsetSeconds = timezone_offset_get( new DateTimeZone($tzinfoIdentifier), new DateTime() );
$offsetFormatted = static::formatOffset($offsetSeconds);
Expand All @@ -98,7 +103,8 @@ public static function get_time_zones($params = []) {
$tzIsBestFitForIdentifier = 1;
if (!empty($otherTzWithIdentifier)) {
foreach ($otherTzWithIdentifier as $otherTz) {
if ($levenshtein < $tzData[$otherTz]['levenshtein']) {
// RG - Check for the presence of the sub-array first
if (isset($tzData[$otherTz]) && $levenshtein < $tzData[$otherTz]['levenshtein']) {
$tzData[$otherTz]['primary'] = 0;
}
else {
Expand Down Expand Up @@ -131,6 +137,7 @@ public static function get_time_zones($params = []) {
date_default_timezone_set($defaultTimeZone);

return $tzData;
// TODO This could be cached
}

private static function formatOffset($offsetSeconds) {
Expand All @@ -146,8 +153,10 @@ private static function formatOffset($offsetSeconds) {
return $offsetFormatted;
}

public static function get_select($params) {
public static function get_select($params)
{
//Deprecated
this->get_select_html($params);
// RG - Fixed reference to static method
return self::get_select_html($params);
}
}

0 comments on commit f3cfa40

Please sign in to comment.