mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-20 11:30:11 +00:00
改进时区问题的解决方案
This commit is contained in:
parent
8145dfcc7c
commit
d0f0b84096
@ -1,22 +1,20 @@
|
||||
# coding=utf-8
|
||||
import datetime
|
||||
from django.utils.timezone import localtime
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
def get_contest_status(contest):
|
||||
now = datetime.datetime.now()
|
||||
if localtime(contest.start_time).replace(tzinfo=None) > now:
|
||||
if contest.start_time > now():
|
||||
return "没有开始"
|
||||
if localtime(contest.end_time).replace(tzinfo=None) < now:
|
||||
if contest.end_time < now():
|
||||
return "已经结束"
|
||||
return "正在进行"
|
||||
|
||||
|
||||
def get_contest_status_color(contest):
|
||||
now = datetime.datetime.now()
|
||||
if localtime(contest.start_time).replace(tzinfo=None) > now:
|
||||
if contest.start_time > now():
|
||||
return "info"
|
||||
if localtime(contest.end_time).replace(tzinfo=None) < now:
|
||||
if contest.end_time < now():
|
||||
return "warning"
|
||||
return "success"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user