From 475fbf1410ba4561430e29ea9ffbda41e5509c28 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 16 Jul 2016 23:12:12 +0000 Subject: [PATCH] add parameter to return the localized date for a location --- controllers/geocode.php | 2 +- p3k/Timezone.php | 4 ++-- p3k/timezone/Result.php | 7 +++++-- views/index.php | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/controllers/geocode.php b/controllers/geocode.php index 5fc8a15..9d036ab 100644 --- a/controllers/geocode.php +++ b/controllers/geocode.php @@ -42,7 +42,7 @@ $app->get('/api/geocode', function() use($app) { $response['full_name'] = $adr->fullName; } - $timezone = p3k\Timezone::timezone_for_location($response['latitude'], $response['longitude']); + $timezone = p3k\Timezone::timezone_for_location($response['latitude'], $response['longitude'], k($params,'date')); if($timezone) { $response['timezone'] = $timezone->name; diff --git a/p3k/Timezone.php b/p3k/Timezone.php index 845e3b2..26a5261 100644 --- a/p3k/Timezone.php +++ b/p3k/Timezone.php @@ -3,7 +3,7 @@ namespace p3k; class Timezone { - public static function timezone_for_location($lat, $lng) { + public static function timezone_for_location($lat, $lng, $date=false) { $start = microtime(true); $tzfile = self::tz_data(); @@ -31,7 +31,7 @@ class Timezone { // echo "Sorted in " . ((microtime(true)-$start)*1000). "ms\n"; if(count($timezones) > 0) - return new timezone\Result($timezones[0][2]); + return new timezone\Result($timezones[0][2], $date); else return null; } diff --git a/p3k/timezone/Result.php b/p3k/timezone/Result.php index 5bbf27e..4ac3d27 100644 --- a/p3k/timezone/Result.php +++ b/p3k/timezone/Result.php @@ -8,8 +8,11 @@ class Result { private $_now; private $_name; - public function __construct($timezone) { - $this->_now = new DateTime(); + public function __construct($timezone, $date=false) { + if($date) + $this->_now = new DateTime($date); + else + $this->_now = new DateTime(); $this->_now->setTimeZone(new DateTimeZone($timezone)); $this->_name = $timezone; } diff --git a/views/index.php b/views/index.php index 2f11c7d..4a4f131 100644 --- a/views/index.php +++ b/views/index.php @@ -20,6 +20,7 @@

Weather