改进时区问题的解决方案
This commit is contained in:
@@ -1,22 +1,20 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import datetime
|
import datetime
|
||||||
from django.utils.timezone import localtime
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
|
||||||
def get_contest_status(contest):
|
def get_contest_status(contest):
|
||||||
now = datetime.datetime.now()
|
if contest.start_time > now():
|
||||||
if localtime(contest.start_time).replace(tzinfo=None) > now:
|
|
||||||
return "没有开始"
|
return "没有开始"
|
||||||
if localtime(contest.end_time).replace(tzinfo=None) < now:
|
if contest.end_time < now():
|
||||||
return "已经结束"
|
return "已经结束"
|
||||||
return "正在进行"
|
return "正在进行"
|
||||||
|
|
||||||
|
|
||||||
def get_contest_status_color(contest):
|
def get_contest_status_color(contest):
|
||||||
now = datetime.datetime.now()
|
if contest.start_time > now():
|
||||||
if localtime(contest.start_time).replace(tzinfo=None) > now:
|
|
||||||
return "info"
|
return "info"
|
||||||
if localtime(contest.end_time).replace(tzinfo=None) < now:
|
if contest.end_time < now():
|
||||||
return "warning"
|
return "warning"
|
||||||
return "success"
|
return "success"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user