WordpressImporter::deduceChannelTimezoneOffset PHP Method

deduceChannelTimezoneOffset() public method

public deduceChannelTimezoneOffset ( $channel )
    function deduceChannelTimezoneOffset($channel)
    {
        # find timezone
        $diffs = array();
        foreach ($channel->getElementsByTagName('item') as $item) {
            if ($item->nodeType !== XML_ELEMENT_NODE) {
                continue;
            }
            $localdate = '';
            $utcdate = '';
            foreach ($item->childNodes as $n) {
                if ($n->nodeType !== XML_ELEMENT_NODE) {
                    continue;
                }
                $nname = '' . $n->nodeName;
                if ($nname === 'wp:post_date') {
                    $localdate = $n->nodeValue;
                } elseif ($nname === 'wp:post_date_gmt') {
                    $utcdate = $n->nodeValue;
                }
            }
            if ($utcdate !== '0000-00-00 00:00:00') {
                # lets guess the timezone. yay
                $diff = strtotime($localdate) - strtotime($utcdate);
                if (isset($diffs[$diff])) {
                    $diffs[$diff]++;
                } else {
                    $diffs[$diff] = 1;
                }
            }
        }
        #var_export($diffs);
        if (count($diffs) === 1) {
            return key($diffs);
        }
        $k = array_keys($diffs);
        $mindiff = min($k[0], $k[1]);
        $difference = max($k[0], $k[1]) - $mindiff;
        if (count($diffs) === 2) {
            #$v = array_values($diffs);
            #echo "distribution ";var_dump(max($v[0],$v[1]) - min($v[0],$v[1]));
            #echo "difference ";var_dump($difference);
            #echo "variation ";var_dump(count($diffs));#floatval(max($k[0],$k[1])) / floatval($mindiff));
            #echo "occurance min/max ", min($v[0],$v[1]), '/', max($v[0],$v[1]), PHP_EOL;
            #echo "offsets min/max ", $mindiff, '/', max($k[0],$k[1]), PHP_EOL;
            if ($difference === $mindiff) {
                return $mindiff;
            }
            # most likely DST causing the variation, so
        }
        gb::log(LOG_WARNING, 'unable to exactly deduce timezone -- guessing %s%d', $mindiff < 0 ? '-' : '+', $mindiff);
        return $mindiff;
    }