Brendan McCollam  committed 3684690

Treat naive datetimes passed as next_run_time as local timezone

  • Participants
  • Parent commits c883c21
  • Branches error_on_offset_naive_datetime

Comments (0)

Files changed (3)

File apscheduler/

 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:

File tests/

 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['trigger'] = BlockingScheduler()._create_trigger(job_kwargs.pop('trigger'),

File tests/

 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)
-    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):