mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-26 17:24:23 -04:00
Merge pull request #578 from alphagov/timezones
Convert timezones using pytz.
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
import dateutil
|
import dateutil
|
||||||
|
import pytz
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask,
|
Flask,
|
||||||
session,
|
session,
|
||||||
@@ -184,38 +184,30 @@ def syntax_highlight_json(code):
|
|||||||
return Markup(highlight(code, JavascriptLexer(), HtmlFormatter(noclasses=True)))
|
return Markup(highlight(code, JavascriptLexer(), HtmlFormatter(noclasses=True)))
|
||||||
|
|
||||||
|
|
||||||
def format_datetime(date):
|
def gmt_timezones(date):
|
||||||
from_zone = dateutil.tz.gettz('UTC')
|
|
||||||
to_zone = dateutil.tz.gettz('Europe/London')
|
|
||||||
date = dateutil.parser.parse(date)
|
date = dateutil.parser.parse(date)
|
||||||
native = date.replace(tzinfo=from_zone)
|
forced_utc = date.replace(tzinfo=pytz.utc)
|
||||||
return native.astimezone(to_zone).strftime('%A %d %B %Y at %H:%M')
|
return forced_utc.astimezone(pytz.timezone('Europe/London'))
|
||||||
|
|
||||||
|
|
||||||
|
def format_datetime(date):
|
||||||
|
return gmt_timezones(date).strftime('%A %d %B %Y at %H:%M')
|
||||||
|
|
||||||
|
|
||||||
def format_datetime_short(date):
|
def format_datetime_short(date):
|
||||||
from_zone = dateutil.tz.gettz('UTC')
|
return gmt_timezones(date).strftime('%d %B at %H:%M')
|
||||||
to_zone = dateutil.tz.gettz('Europe/London')
|
|
||||||
date = dateutil.parser.parse(date)
|
|
||||||
native = date.replace(tzinfo=from_zone)
|
|
||||||
return native.astimezone(to_zone).strftime('%d %B at %H:%M')
|
|
||||||
|
|
||||||
|
|
||||||
def format_time(date):
|
def format_time(date):
|
||||||
from_zone = dateutil.tz.gettz('UTC')
|
return gmt_timezones(date).strftime('%H:%M')
|
||||||
to_zone = dateutil.tz.gettz('Europe/London')
|
|
||||||
date = dateutil.parser.parse(date)
|
|
||||||
native = date.replace(tzinfo=from_zone)
|
|
||||||
return native.astimezone(to_zone).strftime('%H:%M')
|
|
||||||
|
|
||||||
|
|
||||||
def format_date(date):
|
def format_date(date):
|
||||||
date = dateutil.parser.parse(date)
|
return gmt_timezones(date).strftime('%A %d %B %Y')
|
||||||
return date.strftime('%A %d %B %Y')
|
|
||||||
|
|
||||||
|
|
||||||
def format_date_short(date):
|
def format_date_short(date):
|
||||||
date = dateutil.parser.parse(date)
|
return gmt_timezones(date).strftime('%d %B').lstrip('0')
|
||||||
return date.strftime('%d %B').lstrip('0')
|
|
||||||
|
|
||||||
|
|
||||||
def valid_phone_number(phone_number):
|
def valid_phone_number(phone_number):
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ pyexcel-io==0.1.0
|
|||||||
pyexcel-xls==0.1.0
|
pyexcel-xls==0.1.0
|
||||||
pyexcel-xlsx==0.1.0
|
pyexcel-xlsx==0.1.0
|
||||||
pyexcel-ods3==0.1.1
|
pyexcel-ods3==0.1.1
|
||||||
|
pytz==2016.4
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
|
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user