Make datetime output timezone-aware
This commit is contained in:
parent
98a8faf486
commit
d4eb9ae5cf
@ -39,6 +39,7 @@ if is_python:
|
||||
import hashlib
|
||||
import importlib
|
||||
import json
|
||||
import pytz
|
||||
import uuid
|
||||
__pragma__('noskip')
|
||||
else:
|
||||
@ -158,14 +159,14 @@ class DateTimeField(Field):
|
||||
return None
|
||||
|
||||
if is_python:
|
||||
return datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
|
||||
return pytz.utc.localize(datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ'))
|
||||
else:
|
||||
return __pragma__('js', '{}', 'new Date(value)')
|
||||
|
||||
@staticmethod
|
||||
def now():
|
||||
if is_python:
|
||||
return datetime.utcnow()
|
||||
return pytz.utc.localize(datetime.utcnow())
|
||||
else:
|
||||
return __pragma__('js', '{}', 'new Date()')
|
||||
|
||||
|
@ -36,6 +36,7 @@ import functools
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import pytz
|
||||
import subprocess
|
||||
|
||||
app = flask.Flask(__name__, static_folder=None)
|
||||
@ -157,7 +158,8 @@ def inject_globals():
|
||||
|
||||
@app.template_filter('pretty_date')
|
||||
def pretty_date(dt):
|
||||
return flask.Markup('<time datetime="{}" title="{}">{}</time>'.format(dt.strftime('%Y-%m-%dT%H:%M:%SZ'), dt.strftime('%Y-%m-%d %H:%M:%S UTC'), timeago.format(dt, datetime.now())))
|
||||
dt_local = dt.astimezone(pytz.timezone(app.config['TIMEZONE']))
|
||||
return flask.Markup('<time datetime="{}" title="{}">{}</time>'.format(dt_local.strftime('%Y-%m-%dT%H:%M:%S%z'), dt_local.strftime('%Y-%m-%d %H:%M:%S %Z'), timeago.format(dt, DateTimeField.now())))
|
||||
|
||||
# Tickle the plumbus every request
|
||||
@app.before_request
|
||||
|
@ -16,6 +16,8 @@ ADMINS = [
|
||||
|
||||
TASK_RUN_STRATEGY = 'eos.core.tasks.direct.DirectRunStrategy'
|
||||
|
||||
TIMEZONE = 'Australia/Canberra'
|
||||
|
||||
# MongoDB
|
||||
|
||||
DB_TYPE = 'mongodb'
|
||||
|
@ -15,6 +15,7 @@ psutil==5.4.1
|
||||
psycopg2==2.7.3.2
|
||||
PyExecJS==1.4.1
|
||||
pymongo==3.5.1
|
||||
pytz==2017.3
|
||||
requests==2.18.4
|
||||
requests-oauthlib==0.8.0
|
||||
six==1.10.0
|
||||
|
Loading…
Reference in New Issue
Block a user