Times from api are now formatted to the british time.

This commit is contained in:
Nicholas Staples
2016-05-03 10:55:37 +01:00
parent 1965537f30
commit e1f3975c9a
2 changed files with 20 additions and 12 deletions

View File

@@ -173,21 +173,27 @@ def syntax_highlight_json(code):
def format_datetime(date):
from_zone = dateutil.tz.gettz('UTC')
to_zone = dateutil.tz.gettz('Europe/London')
date = dateutil.parser.parse(date)
native = date.replace(tzinfo=None)
return native.strftime('%A %d %B %Y at %H:%M')
native = date.replace(tzinfo=from_zone)
return native.astimezone(to_zone).strftime('%A %d %B %Y at %H:%M')
def format_datetime_short(date):
from_zone = dateutil.tz.gettz('UTC')
to_zone = dateutil.tz.gettz('Europe/London')
date = dateutil.parser.parse(date)
native = date.replace(tzinfo=None)
return native.strftime('%d %B at %H:%M')
native = date.replace(tzinfo=from_zone)
return native.astimezone(to_zone).strftime('%d %B at %H:%M')
def format_time(date):
from_zone = dateutil.tz.gettz('UTC')
to_zone = dateutil.tz.gettz('Europe/London')
date = dateutil.parser.parse(date)
native = date.replace(tzinfo=None)
return native.strftime('%H:%M')
native = date.replace(tzinfo=from_zone)
return native.astimezone(to_zone).strftime('%H:%M')
def format_date(date):

View File

@@ -53,9 +53,10 @@ def test_should_show_api_keys_page(app_,
response = client.get(url_for('main.api_keys', service_id=fake_uuid))
assert response.status_code == 200
assert 'some key name' in response.get_data(as_text=True)
assert 'another key name' in response.get_data(as_text=True)
assert 'Revoked Thursday 01 January 1970 at 00:00' in response.get_data(as_text=True)
resp_data = response.get_data(as_text=True)
assert 'some key name' in resp_data
assert 'another key name' in resp_data
assert 'Revoked Thursday 01 January 1970 at 01:00' in resp_data
mock_get_api_keys.assert_called_once_with(service_id=fake_uuid)
@@ -66,12 +67,13 @@ def test_should_show_name_api_key_page(app_,
mock_get_user_by_email,
mock_get_api_keys,
mock_get_service,
mock_has_permissions):
mock_has_permissions,
fake_uuid):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
service_id = str(uuid.uuid4())
response = client.get(url_for('main.create_api_key', service_id=service_id))
service_id = fake_uuid
response = client.get(url_for('main.create_api_key', service_id=fake_uuid))
assert response.status_code == 200