改进时区问题的解决方案

This commit is contained in:
virusdefender 2015-08-23 14:32:53 +08:00
parent 8145dfcc7c
commit d0f0b84096

View File

@ -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"