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 CiviMail (Moderator: Piotr Szotkowski) »
  • CiviMail not using Drupal-set timezone.
Pages: [1] 2

Author Topic: CiviMail not using Drupal-set timezone.  (Read 13034 times)

samwilson

  • Guest
CiviMail not using Drupal-set timezone.
May 27, 2007, 10:49:32 pm
Using CiviCRM 1.7, when sending 'immediately' using CiviMail, the message is scheduled to be sent 'now' (user's time) but with respect to 'now' (server time).  For example, at 2PM my time I send a message immediately, and it's scheduled to be sent at 9PM my time.  I have got no idea of how it's figuring this out; it doesn't seem at all intuitive.  Has anyone else had this problem?  It's listed as an issue: http://issues.civicrm.org/jira/browse/CRM-1021.

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 27, 2007, 11:01:13 pm
This is strange. CRM_Mailing_BAO_Mailing::create() has the below code handling this:

Code: [Select]
<?php
if ($params['now']) {
    
$job->scheduled_date = date('YmdHis');
} else {
    
$job->scheduled_date =
        
CRM_Utils_Date::format($params['start_date']);
}
?>


This means that if the checkbox is checked, scheduled_date should be set to the current server time.

Are you sure your server’s time is not off by eight hours?

Is there a chance that PHP is running on a different machine than the database?
« Last Edit: May 27, 2007, 11:43:11 pm by Piotr Szotkowski »
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

samwilson

  • Guest
Re: CiviMail not using Drupal-set timezone.
May 27, 2007, 11:25:13 pm
Quote from: Piotr Szotkowski on May 27, 2007, 11:01:13 pm
Is there a chance that PHP is running on a different machine than the database?

Ah!  Yes, that's it.

Could
Code: [Select]
<?php
$job
->scheduled_date = date('YmdHis');
?>
be replaced by something that gets the database time?  I'm not familiar with how it would be done within Drupal, but in SQL it'd be
Code: [Select]
SELECT DATE_FORMAT( NOW( ) , '%Y%m%d%H%i%s' )
In Drupal, would the following work?
Code: [Select]
<?php
$job
->scheduled_date = db_result(db_query("SELECT DATE_FORMAT( NOW( ) , '%Y%m%d%H%i%s' )"));
?>

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 27, 2007, 11:48:31 pm
Quote from: samwilson on May 27, 2007, 11:25:13 pm
Quote from: Piotr Szotkowski on May 27, 2007, 11:01:13 pm
Is there a chance that PHP is running on a different machine than the database?

Ah!  Yes, that's it.

Could
Code: [Select]
<?php
$job
->scheduled_date = date('YmdHis');
?>
be replaced by something that gets the database time?

We’re strongly advising running the database on a separate machine, so if CRM-1021 won’t make it into CiviCRM 1.8, I’ll make sure it’s the database’s NOW() that gets set. Thanks a lot for catching this.

BTW: If your web and database servers are indeed in time zones eight hours apart, they better be connected with some fast pipe; if they’re physically close to each other, their system times shouldn’t differ…
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 27, 2007, 11:53:21 pm
I filed CRM-1952 to be fixed in CiviCRM 1.8.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

samwilson

  • Guest
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 12:08:43 am
Quote from: Piotr Szotkowski on May 27, 2007, 11:48:31 pm
BTW: If your web and database servers are indeed in time zones eight hours apart, they better be connected with some fast pipe; if they’re physically close to each other, their system times shouldn’t differ…

Hmmm.  I should've thought about this a bit more before:  my DB server is in the same TZ as the web server!  So the date/times being returned by PHP's date() and MySQL's NOW() should be the same.  So the problem lies elsewhere...

Any ideas?  :)

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 12:32:26 am
Quote from: samwilson on May 28, 2007, 12:08:43 am
my DB server is in the same TZ as the web server!  So the date/times being returned by PHP's date() and MySQL's NOW() should be the same.

Well, are they or are they not? :) The easiest way to check (if you don’t have shell access) is with phpinfo() for the webserver and a SELECT NOW() query in PHPMyAdmin.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

samwilson

  • Guest
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 12:36:10 am
Oh, no, I meant: yes, they most certainly are the same(!)

So, to schedule for 'now' (Drupal time), would the following work?

Code: [Select]
<?php
$tz_offset 
= variable_get('date_default_timezone', 0);
$sql = "SELECT DATE_FORMAT( DATE_ADD(NOW(), INTERVAL $tz_offset SECOND) , '%Y%m%d%H%i%s' )";
$job->scheduled_date = db_result(db_query($sql));
?>
« Last Edit: May 28, 2007, 12:45:17 am by samwilson »

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 01:02:29 am
Ok, in this case I need access to your box to investigate. Please email me (my GPG key is D128F14A if you want to encrypt anything) or ping me on IM if you can share the credentials.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

samwilson

  • Guest
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 01:33:38 am
It's my client's machine, and I can't really give out details.  Sorry.

But I've discovered that default (i.e. +0000 offset) timezone of Drupal is not in fact the same as the servers' time.  In the date/time settings page, Drupal lists 7:54am as being +0000, but server time is 1:24am.  Am I missing something here? Where is that 6.5 hours going?!  I'm at +1000, which is what's being returned by variable_get('date_default_timezone', 0), and I would've thought that the code I posted earlier would return the correct time, but it doesn't.

Thanks for all your help.

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 01:48:38 am
We don’t really hook to Drupal’s time information in any way (being as much CMS agnostic as we can, as we also run as a Joomla module), so you can take Drupal time out of the equation.

As you can see in the PHP snipped quoted above, we get the webserver’s current time and put it in the database. Your best bet would be to check what time makes it into the database (civicrm_mailing_job.scheduled_date) and whether this is the time that appears later on the mailings selector.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: CiviMail not using Drupal-set timezone.
May 28, 2007, 02:48:50 am
Quote from: samwilson on May 28, 2007, 12:36:10 am
So, to schedule for 'now' (Drupal time), would the following work?

Code: [Select]
<?php
$tz_offset 
= variable_get('date_default_timezone', 0);
$sql = "SELECT DATE_FORMAT( DATE_ADD(NOW(), INTERVAL $tz_offset SECOND) , '%Y%m%d%H%i%s' )";
$job->scheduled_date = db_result(db_query($sql));
?>

Forgot to comment – yes, try that and let us know whether this fixes it for you.
« Last Edit: May 28, 2007, 02:57:33 am by Piotr Szotkowski »
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

msn

  • I post frequently
  • ***
  • Posts: 152
  • Karma: 6
  • Please talk to the other site
Re: CiviMail not using Drupal-set timezone.
August 02, 2007, 03:28:36 pm
I saw this topic is related to my issue, so I place it here.

First a question to samwilson: did your code work? How did you make it work, wich file...?

My issue:
My site is for the Netherland, my server is in Site5 (Dalles) so there is a time diff of 7 hours.

I can change my hosting server time in civicrm.settings.php with the code:
ini_set('date.timezone',        'Europe/Amsterdam');
I checked good working for for activities, send test mail in Civicmail and the reported times in CiviMail report/views

It does not work for send immediatly or schedule a mail in civimail. The send time reported is the Europe/Amsterdam time. But the real send time is de Dallas server time. Is there a way to solve this? Maybe CiviMail can read the TZ from the settings.php?

Is this an issue to be solved? For V1.8 or 2.0?



 

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: CiviMail not using Drupal-set timezone.
August 02, 2007, 04:27:23 pm

We'd like to avoid getting into timezone conversion issues etc as much as possible

If this is important to you / your org, please consider submitting a patch that addresses and fixes the problem. The solution will need to be CMS agnostic (i.e. not tied to drupal's TZ settings)

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

msn

  • I post frequently
  • ***
  • Posts: 152
  • Karma: 6
  • Please talk to the other site
Re: CiviMail not using Drupal-set timezone.
August 06, 2007, 06:20:08 pm
I am not a script writer, but I did take the challenge to go into this issue.

Problem 1: When your servertime is not your local time all the time settings (activities, mailing) are server based, not local as wanted.

Problem 2: Registered scheduled send mail time is not the same time as the time is realy send (start date).
I found out that the registered scheduled send mail time (same time as time for activities) is php based and the timing for the start date is mysql based.

Solution 1:  Make your own costum time zone. In civicrm.settings.php I inserted from line 6:

/**
 * Setup your timezone for local timings in civicrm:
 * For the list of the supported timezones see: http://nl3.php.net/manual/nl/timezones.php
 * Settings for the Netherlands:
 *          ini_set('date.timezone','Europe/Amsterdam');
 * Uncommand and fill in the timezone setting when you have timing differences
 */
#ini_set('date.timezone','             ');

You then have location based timing, only the scheduled timings for sending email is not equal. For that we need also solution 2.

Solution 2: The timing for sending e-mails is in file: civicrm/CRM/Mailing/BAO/Job.php.
From line 65 there is our query:
$query = "  SELECT      *
                    FROM        $jobTable
                    WHERE       (start_date IS null
                        AND         scheduled_date <= NOW()
                        AND         status = 'Scheduled')
                    OR          (status = 'Running'
                        AND         end_date IS null)
                    ORDER BY    scheduled_date, start_date";

In line "scheduled_date <= NOW()" is the comparison, NOW() is mysql based. We can make this line php timezone based bij changing the query and bij adding some codes above the query:

/**
 * Get the php zonetime and compare it with the scheduled start time for mailing
 */
$zonetime = date('H,i,s,m,d,Y', strtotime('now'));
$query = "  SELECT      *
                    FROM        $jobTable
                    WHERE       (start_date IS null
                        AND         scheduled_date <= STR_TO_DATE('$zonetime','%H,%i,%s,%m,%d,%Y')   
                        AND         status = 'Scheduled')
                     OR          (status = 'Running'
                        AND         end_date IS null)
                    ORDER BY    scheduled_date, start_date";

That it. The user has the freedom to make his own choice in local time settings and only has to make an extra setting in civicrm.settings.php.
This is only a solution for working with civicrm in 1 timezone, not for working in differend timezones, but solves the time differences.

This code worked for me (mysql 4.2.1 and php 5.2.1) The php code used is for php4, I did not test this.
I don't know effects in other parts of civicrm, I did not noticed this. I think this code is CMS agnostic, maybe this can be tested by others and when approved implemented in the core civicrm1.8?

Sorry, I don't know how to make a patch of this.

Regards
Martin






Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • CiviMail not using Drupal-set timezone.

This forum was archived on 2017-11-26.