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) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Views: warning: DateTime::__construct()
Pages: [1]

Author Topic: Views: warning: DateTime::__construct()  (Read 2794 times)

fcjversc

  • Guest
Views: warning: DateTime::__construct()
July 02, 2009, 02:24:39 am
Hey!

With Views, when im requesting the field "Event Startdate" to be viewed two times, i get the following error:

warning: DateTime::__construct() [datetime.--construct]: Failed to parse time string (1248265800) at position 7 (8): Unexpected character in /var/www/orbizznet/sites/all/modules/civicrm/drupal/modules/views/civicrm/civicrm_handler_field_datetime.inc on line 23.

I want the field to be viewed twice, because the first view displays the full date and the second field displays the day of the event.

Are you familiar with this problem?

thnx in advance!
greets, Frank

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views: warning: DateTime::__construct()
July 18, 2009, 01:24:21 pm
were you able to get it to display once?
http://www.rootyhollow.com

fcjversc

  • Guest
Re: Views: warning: DateTime::__construct()
August 02, 2009, 06:43:56 am
Yep, when i display it once, the error is gone  :)

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views: warning: DateTime::__construct()
August 02, 2009, 08:58:13 am
It looks like the issue is the data handler in CiviCRM.  Can you accomplish what you want with a custom date format?

The issue is the data handler in CiviCRM converts the date's format to an integer before it can be passed to views.  When the handler is called the second time the field's data is already formatted (from the first pass through the handler) hence the handler fails as it is expecting a different format (this is why the DateTime class is throwing up an error). 

I may be possible to edit the handler to look to see if it's the second time looking at the field.
http://www.rootyhollow.com

mariagwyn

  • I post frequently
  • ***
  • Posts: 149
  • Karma: 4
  • CiviCRM version: CiviCRM 3.3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.2.14
  • PHP version: 5.0.91-50-log
Re: Views: warning: DateTime::__construct()
August 05, 2009, 08:19:38 pm
I am getting the same (I think) error:
Code: [Select]
warning: DateTime::__construct() [datetime.--construct]: Failed to parse time string (1199941200) at position 8 (0):
Unexpected character in /ebs/home/scethics/public_html/sites/all/modules/civicrm/drupal/modules/views/civicrm/civicrm_handler_field_datetime.inc on line 23.

I am setting an argument on an Start_date, granularity: year.  The start date is also a field within the view, set up in a custom way that does NOT show the year (I only want the start day to show day/mm, end date does day/mm/year).  However, the argument is working, it does filter the event information to only the year in the argument.  but the error shows up on all pages.

In addition, the error appears on any page which has a block from this view, even if that block has no corresponding argument.  Also, if the view returns three events, three errors appear.  One event, one error, etc.

UPDATE: the error appears anywhere I have a view with a cividate in it, whether I have an argument or not.  Yuck!

I am not quite sure what the solution "try a custom date format" means in my case since I am just pulling dates from standard event fields to show them in blocks within drupal.  But I do need the argument since I am setting up views/panels based on the year of the event.
« Last Edit: August 05, 2009, 10:19:37 pm by mariagwyn »

mariagwyn

  • I post frequently
  • ***
  • Posts: 149
  • Karma: 4
  • CiviCRM version: CiviCRM 3.3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.2.14
  • PHP version: 5.0.91-50-log
Re: Views: warning: DateTime::__construct()
August 05, 2009, 10:52:28 pm
I just realized that I do indeed have TWO calls on the same date field, I was using one for a title and so was a bit hidden.  I am going to try the customized date field in Events to see if it fixes it.  Will get back if it doesn't.

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Views: warning: DateTime::__construct()
August 10, 2009, 05:29:25 pm
the error in the handler can be fixed  (if you want to dig into code)

by replacing the contents of the handler <Drupal Modules folder>/civicrm/drupal/modules/views/civicrm/civicrm_handler_field_datetime.inc with the code below

Code: [Select]
<?php

/*
 * Unchanged anonymous code contribution. No claim.
 *
 * civicrm_handler_field_datetime.inc
 * Converts and displays text to something views friendly.
 *
 */

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);
        
$value = $values->{$this->field_alias};

        
        if(
is_string($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 - $timezone;

            if(
$value) {
                
$values->{$this->field_alias} = $value;
            }
        }

        return 
parent::render($values);
    }
}

?>

http://www.rootyhollow.com

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Views: warning: DateTime::__construct()

This forum was archived on 2017-11-26.