Fix date/time fuctions for timezone information

This commit is contained in:
2012-05-20 14:23:08 +01:00
parent 0a4b30244f
commit 1bbd15abce
5 changed files with 20 additions and 22 deletions

View File

@@ -5,17 +5,16 @@ from operator import itemgetter
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.utils.timezone import now, utc
from piston.handler import BaseHandler
from piston.utils import rc, throttle
from api.models import AuthAPIKey, AuthAPILog
from eve_proxy.models import CachedDocument
from eve_proxy.exceptions import *
from eve_api.app_defines import *
@@ -54,12 +53,10 @@ class OAuthOpTimerHandler(BaseHandler):
for node in dom.getElementsByTagName('rowset')[0].childNodes:
if node.nodeType == 1:
ownerID = node.getAttribute('ownerID')
ownerID = node.getAttribute('ownerID')
if ownerID != '1':
date = node.getAttribute('eventDate')
dt = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
now = datetime.utcnow()
startsIn = int(dt.strftime('%s')) - int(now.strftime('%s'))
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
duration = int(node.getAttribute('duration'))
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
@@ -84,7 +81,7 @@ class OAuthOpTimerHandler(BaseHandler):
'isImportant': int(node.getAttribute('importance')),
'eventText': node.getAttribute('eventText'),
'endsIn':endsIn,
'forumLink': forumlink}
'forumLink': forumlink}
events.append(event)
if len(events) == 0:
@@ -101,7 +98,7 @@ class OAuthOpTimerHandler(BaseHandler):
'forumLink': ''}]}
else:
events.sort(key=itemgetter('startsIn'))
return {'ops': events, 'doc_time': cached_doc.time_retrieved, 'cache_until': cached_doc.cached_until, 'current_time': datetime.utcnow() }
return {'ops': events, 'doc_time': cached_doc.time_retrieved, 'cache_until': cached_doc.cached_until, 'current_time': now() }
class OAuthCharacterHandler(BaseHandler):