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