2019-10-01 05:25:43 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import ast
|
|
|
|
|
2021-03-16 02:02:17 +00:00
|
|
|
def checkbox(value):
|
|
|
|
return True if value == "on" else False
|
|
|
|
|
|
|
|
|
|
|
|
def safe_int(value):
|
|
|
|
try:
|
|
|
|
return int(value)
|
|
|
|
except:
|
2019-10-01 05:25:43 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def time_to_form(date_time):
|
|
|
|
if date_time == "~T":
|
|
|
|
return datetime.today()
|
|
|
|
elif date_time == "~N":
|
|
|
|
return datetime.now()
|
|
|
|
elif date_time == "~Y":
|
|
|
|
return datetime.today() - timedelta(days=1)
|
|
|
|
elif date_time == "":
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return datetime.utcfromtimestamp(float(date_time))
|
|
|
|
|
|
|
|
|
|
|
|
def form_to_time(date_time):
|
|
|
|
dt = ast.literal_eval(date_time)
|
|
|
|
if dt[0] in ["~T", "~N", "~Y"]:
|
|
|
|
return dt[0]
|
|
|
|
else:
|
|
|
|
dt[0] = dt[0] if dt[0] else datetime.now().strftime("%Y-%m-%d")
|
|
|
|
dt[1] = dt[1] if dt[1] else "00:00:00"
|
|
|
|
return datetime.strptime(" ".join(dt), "%Y-%m-%d %H:%M:%S").timestamp()
|