Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct UTC settings for crontab #300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ross-spencer
Copy link

Connected to: #299

@resulyrt93
Copy link

hi team, what is the last status about this task?

@Harsh-Maheshwari
Copy link

FutureWarning: Version 0.22.0+ of crontab will use datetime.utcnow() and
datetime.utcfromtimestamp() instead of datetime.now() and
datetime.fromtimestamp() as was previous. This had been a bug, which will be
remedied. If you would like to keep the *old* behavior:
`ct.next(..., default_utc=False)` . If you want to use the new behavior *now*:
`ct.next(..., default_utc=True)`. If you pass a datetime object with a tzinfo
attribute that is not None, timezones will *just work* to the best of their
ability. There are tests...
  next_time = cron.next(now=now, return_datetime=True)

Is this warning being solved in this thread?

canhlinh

This comment was marked as off-topic.

@@ -23,7 +23,7 @@ def to_unix(dt):
def get_next_scheduled_time(cron_string, use_local_timezone=False):
"""Calculate the next scheduled time by creating a crontab object
with a cron string"""
now = datetime.now()
now = datetime.now(timezone.utc)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better

    tz = dateutil.tz.tzlocal() if use_local_timezone else dateutil.tz.UTC
    now = datetime.now(tz)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants