Browse Source

add parameter to return the localized date for a location

main
Aaron Parecki 8 years ago
parent
commit
475fbf1410
4 changed files with 9 additions and 5 deletions
  1. +1
    -1
      controllers/geocode.php
  2. +2
    -2
      p3k/Timezone.php
  3. +5
    -2
      p3k/timezone/Result.php
  4. +1
    -0
      views/index.php

+ 1
- 1
controllers/geocode.php View File

@ -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;

+ 2
- 2
p3k/Timezone.php View File

@ -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;
}

+ 5
- 2
p3k/timezone/Result.php View File

@ -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;
}

+ 1
- 0
views/index.php View File

@ -20,6 +20,7 @@
<ul>
<li><a href="/api/geocode?latitude=45.5118&amp;longitude=-122.6433">/api/geocode?latitude=45.5118&amp;longitude=-122.6433</a></li>
<li><a href="/api/geocode?latitude=45.5118&amp;longitude=-122.6433&date=2016-07-12T09:00:00Z">/api/geocode?latitude=45.5118&amp;longitude=-122.6433&date=2016-07-012T09:00:00Z</a> and return the local time of the given timestamp</li>
</ul>
<h2><i class="fa fa-sun-o"></i> Weather</h2>

Loading…
Cancel
Save