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 CiviContribute (Moderator: Donald Lobo) »
  • Wrong contribution time in Receipt E-mails
Pages: [1]

Author Topic: Wrong contribution time in Receipt E-mails  (Read 10727 times)

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Wrong contribution time in Receipt E-mails
November 11, 2012, 07:55:28 pm
Using CiviCRM 4.2.4, Wordpress 3.4.2 and Paypal Payments Pro, CiviCRM seems to be having a hard time with... well, time.

I made a test donation on a site whose server time was 8:38pm (CST). Paypal, which is on PST, naturally sent back an IPN saying the donation occurred at 6:38 PM. What CiviCRM reported for the transaction (and used in the receipt, etc.) was 2:38 AM the next day. I have no idea where it could possibly have picked up those extra eight hours, but it's obviously a bit of a problem...

I've seen people elsewhere wrestling with CiviCRM taking time from their server instead of local time, but in this instance, CiviCRM seems to be simply arbitrarily adding eight hours to the time, so I have no idea where to start on fixing it. Any advice would be much appreciated.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Wrong contribution time in Receipt E-mails
November 12, 2012, 08:29:33 am

CiviCRM does not have any timezone support as yet. This is a missing feature and we hope to rectify it  in a future release

Currently Civi inherits the timezone from php. So most likely your php.ini is set for GMT which is approx 8 hours ahead of PST

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Jason W

  • I post frequently
  • ***
  • Posts: 197
  • Karma: 12
  • jason@civitrainingtutorials.com
  • CiviCRM version: 4.2
  • CMS version: Drupal 7
  • MySQL version: 5.x
  • PHP version: 5.x.x
Re: Wrong contribution time in Receipt E-mails
November 12, 2012, 08:39:21 am
Hello grandesigns,

This issue has popped up on the forums once or twice before. WP has a built in timezone that resides in the General tab of the admin console, but Civi pulls the TZ from line 32 of the php.ini file. here's a couple of resources that should help you out.

http://name1price.com/how-to-get-customers-with-singapore-web-design-basic/wordpress-tutorials/128-setting-the-default-timezone-in-wordpress.html

And also:
http://forum.civicrm.org/index.php/topic,26132.msg110506.html#msg110506

Cheers,
Jason
civiTrainingTutorials
"Helping You Help Others"

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Wrong contribution time in Receipt E-mails
November 12, 2012, 11:49:46 am
Quote from: Donald Lobo on November 12, 2012, 08:29:33 am
Currently Civi inherits the timezone from php. So most likely your php.ini is set for GMT which is approx 8 hours ahead of PST

Quote from: Jason W on November 12, 2012, 08:39:21 am
Civi pulls the TZ from line 32 of the php.ini file.

Donald and Jason, thank you for the insight, but unfortunately I don't think we're barking up quite the right tree:

I checked and found that the time zone in my php.ini file was set to CST, not GMT as supposed above. I changed it to EST, and now running
Code: [Select]
echo date('l jS \of F Y h:i:s A'); produces the correct (local) time, but CiviCRM is still spitting out times in GMT/UTC.

I do notice that in my php.ini file the time is set on line 13 (as date.timezone = America/Detroit) rather than on line 32 as Jason anticipated above. Could it be that CiviCRM is somehow failing to read the time from the php.ini file (either due to this or another issue - possibly a problem with the path?), and therefore defaulting to GMT/UTC?
« Last Edit: November 12, 2012, 11:51:47 am by grandesigns »

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Wrong contribution time in Receipt E-mails
November 12, 2012, 01:24:30 pm
Make a file with the following and call it from a browser. It will tell you where it's getting stuff from:

Code: [Select]
<?php
phpinfo
();
?>


grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Wrong contribution time in Receipt E-mails
November 12, 2012, 03:13:11 pm
Quote from: demeritcowboy on November 12, 2012, 01:24:30 pm
Make a file with the following and call it from a browser. It will tell you where it's getting stuff from:

Results are:

Quote
Configuration File (php.ini) Path   /opt/php53/lib
Loaded Configuration File   /home/gleaners/php.ini

and

Quote
date

date/time support   enabled
"Olson" Timezone Database Version   2012.3
Timezone Database   internal
Default timezone   America/Detroit

Directive   Local Value   Master Value
date.default_latitude   31.7667   31.7667
date.default_longitude   35.2333   35.2333
date.sunrise_zenith   90.583333   90.583333
date.sunset_zenith   90.583333   90.583333
date.timezone   America/Detroit   America/Detroit

Making the same thing for another domain on the server (that does not have its own .ini file) produces:

Quote
Configuration File (php.ini) Path   /usr/lib
Loaded Configuration File   /usr/local/lib/php.ini

and

Quote
date/time support   enabled
"Olson" Timezone Database Version   2010.9
Timezone Database   internal
Default timezone   America/Chicago

Directive   Local Value   Master Value
date.default_latitude   31.7667   31.7667
date.default_longitude   35.2333   35.2333
date.sunrise_zenith   90.583333   90.583333
date.sunset_zenith   90.583333   90.583333
date.timezone   no value   no value

So, I guess this means that CiviCRM is ignoring the loaded .ini file in exchange for the default one, and then is ignoring the default timezone in favor of date.timezone, which is unset, and thus it is defaulting to GMT?

Does that sound right? And if so, is there any way to fix that without altering the default .ini file (which I can't do because it's a shared hosting environment)? It seems like somewhere in the depths of CiviCRM there ought to be some code that could be tweaked, but I have no idea where to look for it....

EDIT - This indeed seems to be the same issue that jimurl was wrestling with here: http://forum.civicrm.org/index.php/topic,26132.msg110506.html#msg110506
but unfortunately he did not come up with a fix that applies to my situation - as he said:

Quote from: jimurl on September 19, 2012, 02:57:54 pm
But when the CiviMail cron job ran, it wasn't 'bootstrapping' drupal; in fact it doesn't seem to know which domain environment it is running under; it inherits the master default timezone setting.

In this case, I could set this by editing the main php.ini file ( it was at /usr/local/lib/php.ini in my case). Not all installations have this as an option.
« Last Edit: November 12, 2012, 03:35:38 pm by grandesigns »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Wrong contribution time in Receipt E-mails
November 12, 2012, 08:36:43 pm

civi  does not decide what .ini file php reads to intialize various settings. It makes the assumption that the settings are valid and uses them as is

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Wrong contribution time in Receipt E-mails
November 14, 2012, 02:15:33 pm
Quote from: Donald Lobo on November 12, 2012, 08:36:43 pm
civi  does not decide what .ini file php reads to intialize various settings. It makes the assumption that the settings are valid and uses them as is

Lobo - simply running date() produces the correct time. PHP knows what time zone it is working with, CiviCRM does not. Therefore, CiviCRM is, at some level, making a choice that is different from what a "normal" php script would do. To all appearances, CiviCRM is not "using the settings as they are" - it is disregarding them, and doing something else.
« Last Edit: November 14, 2012, 03:05:14 pm by grandesigns »

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Wrong contribution time in Receipt E-mails
November 14, 2012, 03:41:59 pm
Update for anyone else with this problem:

It's ugly, and not daylight savings time or update proof, but it looks like you can work around this problem, whatever it is, by simply changing a section of code in civicrm/civicrm/CRM/Utils/date.php from:

Code: [Select]
// if date is not passed assume it as today
                                    if (!$mysqlDate) {
                                      $mysqlDate = date('Y-m-d G:i:s');
                                    }

to

Code: [Select]
// if date is not passed assume it as today
                                    if (!$mysqlDate) {
                                      $mysqlDate = date('Y-m-d G:i:s',strtotime('-5 hours'));
                                    }

Obviously adjusting the number of hours as needed for your situation. I still have to confirm that it works for everything I need it to, but the readily observable things (such as default times for manually entering contributions) look to be behaving properly. Will update after I get to run a test contribution.

UPDATE: This does not seem to fix CiviCRM's treatment of donations made through campaign pages. Guess I have another process to trace...

UPDATE 2: What's very strange about all of this is that my log file has the times correct....
« Last Edit: November 14, 2012, 09:48:25 pm by grandesigns »

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Wrong contribution time in Receipt E-mails
November 15, 2012, 02:05:05 pm
Update on the above - in search of a more universal solution, I added

Code: [Select]
date_default_timezone_set('America/Detroit');
to civicrm.php. This seems to have had the desired impact on everything I care about, including most notably the transaction time listed in e-mail receipts. Still ugly and not update proof, but it works, which is more than I can say for relying on php.ini.

Guy Iaccarino

  • I post occasionally
  • **
  • Posts: 92
  • Karma: 5
    • Greenleaf Advancement
  • CiviCRM version: 4.4.10, 4.5.4
  • CMS version: WordPress 4, Drupal 7, Drupal 6, Joomla 3
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Wrong contribution time in Receipt E-mails
February 08, 2013, 11:06:58 am
grandesigns, thanks, this worked great. Like you said, not pretty or upgrade proof, but it works, and easy enough to do for now. Thank you again.
Guy Iaccarino
www.greenleafadvancement.com

grandesigns

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 1
  • CiviCRM version: 4.4.20
  • CMS version: Wordpress
Re: Wrong contribution time in Receipt E-mails
February 09, 2013, 09:17:45 pm
Guyiac - Glad it helped! :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Wrong contribution time in Receipt E-mails

This forum was archived on 2017-11-26.