Adjust date field inputs to UTC


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. $dates = &$query->where['date']['clauses'];
  12. foreach($dates as &$date) {
  13. '(\d{4}-\d{2}-\d{2})',
  14. create_function('$date','return strftime("%Y-%m-%d %H:%M:%S", strtotime($date[0]." '.$tz.'"));'),
  15. $date
  16. );
  17. }
  18. }
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.