Я только что проверил ваш код, и, после назначения вручную каждой переменной, похоже, это работает.Я не изменил ничего, кроме замены strftime("%s")
на timestamp()
, потому что я получал ошибку: ValueError: Invalid format string
.
import datetime
import time
order_id = 0
# Manually assign this
order_date = "2018-12-17T16:58:00-06:00"
customer_is_blocked = False
two_month_seconds = (3600 * 24) * 60
one_month_seconds = (3600 * 24) * 30
stripped_date = order_date[:order_date.find("T")]
current_timestamp = time.time()
# This is the only change I did: strftime("%s") => timestamp()
retrieved_timestamp = int(datetime.datetime.strptime(stripped_date, "%Y-%m-%d").timestamp())
print("one month", one_month_seconds)
print("two months", two_month_seconds)
print("current timestamp", current_timestamp)
print("retrieved timestamp", retrieved_timestamp)
print("current - two months", current_timestamp - two_month_seconds)
if retrieved_timestamp > (current_timestamp - one_month_seconds) and not customer_is_blocked:
print(1)
elif customer_is_blocked:
print(2)
elif retrieved_timestamp < (current_timestamp - two_month_seconds):
print(3)
Со значением order_date
, которое вы указали, код выше печатает 1
если customer_is_blocked == False
и 2
если customer_is_blocked == True
.
Дайте мне знать, если это сработало для вас!