Posted By

terrencewood on 10/14/09


Tagged

date timezone utc drupal views tz


Versions (?)

Adjust date field inputs to UTC


 / Published in: PHP
 

  1. /**
  2.  * Implements hook_views_query_alter
  3.  * - If the db doesn't have timezone support transform exposed filter date inputs from the sites default timezone to UTC.
  4.  * @TODO - can the conversion to UTC happen somewhere in the $view->handler, hook_form_alter, or date api
  5.  */
  6.  
  7. function mymodule_views_query_alter(&$view, &$query) {
  8.  
  9. if(isset($query->where['date']['clauses']) && !variable_get('date_db_tz_support', 0)) {
  10. $tz = variable_get('date_default_timezone_name', 'Pacific/Auckland');
  11. date_default_timezone_set('UTC');
  12. $dates = &$query->where['date']['clauses'];
  13. foreach($dates as &$date) {
  14. '(\d{4}-\d{2}-\d{2})',
  15. create_function('$date','return strftime("%Y-%m-%d %H:%M:%S", strtotime($date[0]." '.$tz.'"));'),
  16. $date
  17. );
  18. }
  19. date_default_timezone_set($tz);
  20. }
  21. }

Report this snippet  

You need to login to post a comment.