title: Celery scheduled tasks problems with Timezone
body: <p>I'm using celery in a server where server time is now <strong>BST</strong>, and suddenly my scheduled tasks are executing <strong>one hour before!</strong> Previously, server time was Europe/London which was GMT but now due to day light saving it has become BST (GMT + 1)</p>
  
  <p>I've configured celery to use the timezone like:</p>
  
  <pre><code>CELERY_TIMEZONE = 'Europe/London'
  </code></pre>
  
  <p>Then when calling tasks, I've also localized value for the <code>eta</code> parameter to 'Europe/London' like this:</p>
  
  <pre><code>from datetime import datetime
  from pytz import timezone
  
  locale_to_use = timezone('Europe/London')
  current_time = locale_to_use.localize(datetime.now())
  </code></pre>
  
  <p>And used this <code>current_time</code> as value of <code>eta</code> parameter when calling task.</p>
  
  <p>Now <strong>is there any mistake I'm making like localizing the <code>eta</code> parameter value</strong>? My server is in BST.</p>
  
  <p>No problems were hapenning with this configuration before the day light saving timezone was in effect!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>To make things clear, I'm posting my code samples here:</p>
  
  <pre><code>@app.task(ignore_result=True)
  def eta_test():
  
      logger.info('Executing eta_test on {0}'.format(datetime.now()))
  
  
  def run_eta_test(hour, minute):
  
      now_time = datetime.now()
      target_time = now_time.replace(hour=hour, minute=minute, second=0)
  
      from settings import options
      from pytz import timezone
  
      local_zone = timezone('Europe/London')
  
      target_time = local_zone.localize(target_time)
  
      eta_test.apply_async(eta=target_time)
  </code></pre>
  
  <p>Then I call run_eta_test from a python console in the server, like this:</p>
  
  <pre><code>test_tasks.run_eta_test(17, 17)
  </code></pre>
  
  <p>That is, to execute the task on 17:17:00 on the same day. The server time was 17:15:45 and instead of scheduling it 2 seconds after, it executed the task immediately:</p>
  
  <pre><code>[2014-04-04 17:15:45,341: INFO/MainProcess] Received task: scheduling.test_tasks.eta_test[c28448d6-3a51-42f7-9df2-cb93385ff7c6] eta:[2014-04-04 17:17:00.095001+01:00]
  [2014-04-04 17:15:46,820: INFO/Worker-3] Executing eta_test on 2014-04-04 17:15:46.820316
  [2014-04-04 17:15:46,820: INFO/MainProcess] Task scheduling.test_tasks.eta_test[c28448d6-3a51-42f7-9df2-cb93385ff7c6] succeeded in 0.0008487419690936804s: None
  </code></pre>
  
  <p>Then I called the task again to be executed 1 hour and few seconds later by calling like:</p>
  
  <pre><code>test_tasks.run_eta_test(18, 17)
  </code></pre>
  
  <p>And instead of scheduling it to one hour and few seconds later, the task executed only few seconds later, that is one hour before:</p>
  
  <pre><code>[2014-04-04 17:16:27,703: INFO/MainProcess] Received task: scheduling.test_tasks.eta_test[f1a54d08-c12d-457f-bee8-04ca35b32242] eta:[2014-04-04 18:17:00.700327+01:00]
  [2014-04-04 17:17:01,846: INFO/Worker-2] Executing eta_test on 2014-04-04 17:17:01.846561
  [2014-04-04 17:17:01,847: INFO/MainProcess] Task scheduling.test_tasks.eta_test[f1a54d08-c12d-457f-bee8-04ca35b32242] succeeded in 0.0012819559779018164s: None
  </code></pre>
  
  <p>My server date is configured to BST like:</p>
  
  <pre><code>Fri Apr  4 17:29:10 BST 2014
  </code></pre>
  
  <p>Now, is the timezone in the server  is being an issue?</p>
  
  <p><strong>Edited Again:</strong></p>
  
  <p>I was not able to solve the problem with the help of the answer and comments. So what I did is, used: <code>CELERY_ENABLE_UTC = False</code> and did not use any value for <code>CELERY_ENABLE_UTC</code> at all. Then, I used my server time without any localization. Celery seemed to schedule tasks correctly at my server time. </p>