fmbiete / Z-Push-contrib

Z-Push fork with changes that I will try to contrib
GNU Affero General Public License v3.0
134 stars 62 forks source link

TimezoneUtil no MS name found for... #291

Open nh-mike opened 7 years ago

nh-mike commented 7 years ago

Hi all,

For quite some time now, my z-push server has been receiving a timezone from a couple of devices (both iPhones 6 or 7) which is not supported by Z-Push. The timezone we are having problems with is as per below: W. Australia Standard Time

I notice, however, that while it is not exactly in the TimezoneUtil file, a nearly identical one is: W Australia Standard Time (no full stop).

Rather than adding another one, I feel that it may be more beneficial to calculate the difference between the 2 strings. Therefore, I would like to suggest an ammendment to the getMSTZnameFromTZName function. I have run this modification live for the past week and feel that maybe it may be suitable for the z-push project. As commented out below, I have added this between the 2nd and 3rd foreach loops in this function.

        foreach (self::$phptimezones as $tzn => $phptzs) {
            if (in_array($name, $phptzs)) {
                $tzName = $tzn;
                break;
            }
        }

/*
    //If timezone name not found, try and find the closest match
    if ($tzName == '') {
        $closesttzn = -1;
        $perc = 0;
        $testperc = 0;
        foreach (self::$phptimezones as $tzn => $phptzs) {
            if ( $closesttzn === -1 ) {
                $closesttzn = $tzn;
            } else {
                similar_text($tzn, $name, $testperc);
                if ( $testperc > 95 && ($perc < $testperc) ) {
                    //If the strings are at least a 95% match and the new one is a better match than the last one
                    $perc = $testperc;
                    $tzName = $tzn;
                }
            }
        }
    }
*/

        if ($tzName != '') {
            foreach (self::$mstzones as $mskey => $msdefs) {
                if ($tzName == $msdefs[0])
                    return $msdefs[1];
            }
        }

To view this code in action: here To view the code itself: here

Cheers.