SRNI-2005/ctf
0
1import time2from datetime import datetime as DateTime3from typing import Union4 5from CTFd.utils import get_config6 7 8def ctftime():9 """Checks whether it's CTF time or not."""10 11 start = get_config("start")12 end = get_config("end")13 14 if start:15 start = int(start)16 else:17 start = 018 if end:19 end = int(end)20 else:21 end = 022 23 if start and end:24 if start < time.time() < end:25 # Within the two time bounds26 return True27 28 if start < time.time() and end == 0:29 # CTF starts on a date but never ends30 return True31 32 if start == 0 and time.time() < end:33 # CTF started but ends at a date34 return True35 36 if start == 0 and end == 0:37 # CTF has no time requirements38 return True39 40 return False41 42 43def ctf_paused():44 return bool(get_config("paused"))45 46 47def ctf_started():48 return time.time() > int(get_config("start") or 0)49 50 51def ctf_ended():52 if int(get_config("end") or 0):53 return time.time() > int(get_config("end") or 0)54 return False55 56 57def view_after_ctf():58 return get_config("view_after_ctf")59 60 61def unix_time(dt: DateTime) -> int:62 if dt is None or not isinstance(dt, DateTime):63 print("Invalid datetime object for time filter function.")64 return None65 return int((dt - DateTime(1970, 1, 1)).total_seconds())66 67 68def unix_time_millis(dt: DateTime) -> int:69 ut = unix_time(dt)70 if ut is None:71 return None72 return ut * 100073 74 75def unix_time_to_utc(t: Union[int, float]) -> DateTime:76 if t is None:77 print("Invalid datetime object for time filter function.")78 return None79 # TODO: The utcfromtimestamp() has been deprecated80 return DateTime.utcfromtimestamp(t)81 82 83def isoformat(dt: DateTime) -> str:84 if dt is None or not isinstance(dt, DateTime):85 print("Invalid datetime object for time filter function.")86 return None87 return dt.isoformat() + "Z"88 