You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
872 B

  1. <?php
  2. $app->get('/api/timezone', function() use($app) {
  3. $params = $app->request()->params();
  4. if(k($params, 'latitude') !== null && k($params, 'longitude') !== null) {
  5. $lat = (float)$params['latitude'];
  6. $lng = (float)$params['longitude'];
  7. $timezone = \p3k\Timezone::timezone_for_location($lat, $lng);
  8. if($timezone) {
  9. json_response($app, [
  10. 'timezone' => $timezone->name,
  11. 'offset' => $timezone->offset,
  12. 'seconds' => $timezone->seconds,
  13. 'localtime' => $timezone->localtime
  14. ]);
  15. } else {
  16. json_response($app, [
  17. 'error' => 'not_found',
  18. 'error_description' => 'No timezone was found for the requested location'
  19. ]);
  20. }
  21. } else {
  22. json_response($app, [
  23. 'error' => 'invalid_request',
  24. 'error_description' => 'Request was missing parameters'
  25. ], 400);
  26. }
  27. });