Commits

Brendan McCollam committed 3684690

Treat naive datetimes passed as next_run_time as local timezone

Comments (0)

Files changed (3)

apscheduler/job.py

 from uuid import uuid4
 
 import six
+from tzlocal import get_localzone
 
 from apscheduler.triggers.base import BaseTrigger
 from apscheduler.util import ref_to_obj, obj_to_ref, datetime_repr, repr_escape, get_callable_name, check_callable_args
             if value and not isinstance(value, datetime):
                 raise TypeError('next_run_time must be either None or a datetime instance')
             if value and value.tzinfo is None:
-                value = self._scheduler.timezone.localize(value)
+                value = get_localzone().localize(value)
             approved['next_run_time'] = value
 
         if changes:

tests/conftest.py

 @pytest.fixture(scope='session')
 def create_job(job_defaults):
     def create(**kwargs):
-        scheduler_ = Mock(BaseScheduler)
-        scheduler_.timezone = timezone()
-        kwargs.setdefault('scheduler', scheduler_)
+        kwargs.setdefault('scheduler', Mock(BaseScheduler))
         job_kwargs = job_defaults.copy()
         job_kwargs.update(kwargs)
         job_kwargs['trigger'] = BlockingScheduler()._create_trigger(job_kwargs.pop('trigger'),

tests/test_job.py

 
 import pytest
 import six
+from tzlocal import get_localzone
 
 from apscheduler.job import Job
 from apscheduler.schedulers.base import BaseScheduler
     """Tests that passing a datetime object without timezone information will get
     automatically localized to the timezone of the parent scheduler."""
 
-    scheduler_tz = job._scheduler.timezone
+    local_tz = get_localzone()
     naive_datetime = datetime(2011, 4, 3, 18, 40)
     job._modify(next_run_time=naive_datetime)
-    assert job.next_run_time == scheduler_tz.localize(naive_datetime)
+    assert job.next_run_time == local_tz.localize(naive_datetime)
 
 
 def test_private_modify_bad_argument(job):