0

The time_machine module in python keeps setting a time that is one day earlier than the date that I set.

I must be missing something obvious!

Here's an example of a simple program showing the discrepancy:

import time_machine
import datetime as dt

def main():
    print(timemachine())
    print(today_time())

def timemachine():
    with time_machine.travel(dt.datetime(2024, 7, 24), tick = False):
        return dt.date.today().isoformat()
def today_time():
    return dt.datetime.today()

if __name__ == "__main__":
    main()

Output: 2024-07-23 -> That's the output for dt.datetime(2024, 7, 24), which is a day earlier. 2024-07-25 11:38:30.354514 -> That's the output for today's date, to ensure that there's nothing wrong with datetime.

3
  • What time zone are you in? Commented Jul 25, 2024 at 16:48
  • i am in Eastern Standard Time, UTC -5 Commented Jul 27, 2024 at 21:17
  • make sure to set correct time zones, for both the time-machine module as well as datetime.today. They show the first on their landing page on pypi: pypi.org/project/time-machine Commented Jul 29, 2024 at 7:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.