CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 3.4 and 4.0 Releases Testing »
  • Possible Error in Views Date Handler: civicrm_handler_field_datetime.inc (4.0)
Pages: [1]

Author Topic: Possible Error in Views Date Handler: civicrm_handler_field_datetime.inc (4.0)  (Read 2586 times)

lkacenja

  • I’m new here
  • *
  • Posts: 18
  • Karma: 2
Possible Error in Views Date Handler: civicrm_handler_field_datetime.inc (4.0)
June 23, 2011, 10:26:07 am
Hopefully this is already resolved or just a problem specific to our installation of Civi 4.0 and Drupal 7. Searched around and didn't see any posts on the subject. Think I found a problem in civicrm/drupal/views/civicrm/civicrm_handler_field_datetime.inc. Looks like $timezone = variable_get('date_default_timezone', 0); is expected to be an offset in seconds, Drupal 7 returns the offset string name i.e. 'america/denver', 'europe/london', 'utc' etc. Later on $value, which is a timestamp gets $timezone subtracted from it ($value = $value - $timezone;). The results were unpredictable as timezone was a string. I've added some additional handling to fix the problem. Don't seem to be able to attach .inc, so here it is:

Code: [Select]
class civicrm_handler_field_datetime extends views_handler_field_date {

    /*
     * Convert the DATETIME from the database into unixtime then allow
     * views_handler_field_date to render as usual.
     * Also trick php into thinking the time is in the same timezone, no
     * matter the default timezone
     */
    function render($values) {
        // get default time zone form Drupal
        $timezone = variable_get('date_default_timezone', 0);

        $origin_dtz = new DateTimeZone('UTC');
        $remote_dtz = new DateTimeZone($timezone);
        $origin_dt = new DateTime("now", $origin_dtz);
        $remote_dt = new DateTime("now", $remote_dtz);
        $local_offset = $origin_dtz->getOffset($origin_dt) - $remote_dtz->getOffset($remote_dt);
       
        $value = $values->{$this->field_alias};

       
        if(is_string($value) && strpos($value,"-")) {
            $date = new DateTime($value);
            $gmt = $date->getOffset();  //gives me the offset to GMT
            $value = strtotime($value);
             //set the timestamp to GMT
            $value = $value + $gmt;
            //set the timestamp to site default
            $value = $value - $local_offset;
           
            if($value) {
                $values->{$this->field_alias} = $value;
            }
        }

        return parent::render($values);
    }
}
Leo Kacenjar
Web Developer
Open Media Foundation

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Possible Error in Views Date Handler: civicrm_handler_field_datetime.inc (4.0)
June 24, 2011, 05:15:30 am
This might be related issue: http://issues.civicrm.org/jira/browse/CRM-8284

Kurund
Found this reply helpful? Support CiviCRM

lkacenja

  • I’m new here
  • *
  • Posts: 18
  • Karma: 2
Re: Possible Error in Views Date Handler: civicrm_handler_field_datetime.inc (4.0)
June 24, 2011, 07:12:14 am
Indeed, I think they are the same. Looks like a  patch has already been filed. Thanks Kurund.
Leo Kacenjar
Web Developer
Open Media Foundation

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 3.4 and 4.0 Releases Testing »
  • Possible Error in Views Date Handler: civicrm_handler_field_datetime.inc (4.0)

This forum was archived on 2017-11-26.