diff --git a/inc/Feed.php b/inc/Feed.php index f8ff2de..ad1667d 100644 --- a/inc/Feed.php +++ b/inc/Feed.php @@ -28,6 +28,12 @@ class Feed extends PhpObject { 'iconSet' => 'icons2' ); + //Timezone + const TIMEZONE_HOOK = 'http://api.geonames.org/timezoneJSON'; + const TIMEZONE_PARAM = array( + 'username' => Settings::TIMEZONE_USER + ); + //DB Tables const SPOT_TABLE = 'spots'; const FEED_TABLE = 'feeds'; @@ -202,7 +208,7 @@ class Feed extends PhpObject { 'longitude' => $asMsg['longitude'], 'iso_time' => $asMsg['dateTime'], //ISO 8601 time (backup) 'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time - 'timezone' => Spot::getTimeZoneFromDate($asMsg['dateTime']), //Local Time Zone + 'timezone' => $this->getTimeZone(array($asMsg['latitude'], $asMsg['longitude']), $asMsg['unixTime']), 'unix_time' => $asMsg['unixTime'], //UNIX Time (backup) 'content' => $asMsg['messageContent'], 'battery_state' => $asMsg['batteryState'] @@ -256,6 +262,17 @@ class Feed extends PhpObject { ); } + private function getTimeZone($asLatLng, $iTimeStamp) { + $asParams = self::TIMEZONE_PARAM; + $asParams['lat'] = $asLatLng[0]; + $asParams['lng'] = $asLatLng[1]; + $sApiUrl = self::TIMEZONE_HOOK.'?'.http_build_query($asParams); + + $asTimeZone = json_decode(file_get_contents($sApiUrl), true); + + return $asTimeZone['timezoneId'] ?? Settings::TIMEZONE; + } + private function retrieveFeed() { $sContent = '[]'; if($this->sRefFeedId !='') { diff --git a/settings-sample.php b/settings-sample.php index 86d8687..6b0b3cf 100755 --- a/settings-sample.php +++ b/settings-sample.php @@ -14,5 +14,6 @@ class Settings const MAIL_USER = ''; const MAIL_PASS = ''; const WEATHER_TOKEN = ''; //visualcrossing.com + const TIMEZONE_USER = ''; //geonames.org const DEBUG = true; }