dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.86k stars 966 forks source link

Issue with timezone/ linux #592

Closed dshetyo closed 1 year ago

dshetyo commented 1 year ago

I am using following code to schedule a function in EST time zone.

The function is scheduled on time on windows machine whose timezone is PST. The function is NOT scheduled on time on linux machine (GCP cloud) whose timezone is UTC.

When I say on time i mean 9:45 EST. I want to function to be scheduled at 9:45 EST irrespective of machine timezone.

def run_live_traders_in_parallel() (self):
    print(f"hello {datetime.datetime.now()}")

def schedule_job(self):
    print(f"schedules jobs")
    schedule.every().day.at("09:45", "US/Eastern").do(self.run_live_traders_in_parallel)

    while True:
        schedule.run_pending()
        print("Scheduled jobs:", schedule.jobs)
        time.sleep(1)
OP from linux machine which is in UTC
 print("Scheduled jobs:", schedule.jobs)
Scheduled jobs: [Every 1 day at 09:45:00 do run_live_traders_in_parallel() (last run: [never], next run: 2023-07-15 13:45:00)

What can be a potential issue?

SijmenHuizenga commented 1 year ago

Resolved with https://github.com/dbader/schedule/pull/583 and released in 1.2.1. I am also adding a test to cover your specific case in #602. Cheers!