Skip to content
Snippets Groups Projects
Commit cf9cbf4e authored by Brian Moe's avatar Brian Moe
Browse files

Time display modifications.

Changed display of all date/time data to be UTC.
GPS times display UTC times when cursor hovers over them.
parent c21a77c4
No related branches found
No related tags found
No related merge requests found
from django import template
from django.conf import settings
from django.utils import dateformat
import pytz
# DATETIME_SETTINGS is guaranteed to be set. GRACE_DATETIME_FORMAT is not.
FORMAT = getattr(settings, 'GRACE_DATETIME_FORMAT', settings.DATETIME_FORMAT)
LOCAL_TZ = pytz.timezone(settings.TIME_ZONE)
register = template.Library()
@register.filter(name='utc')
def utc(dt, format=FORMAT):
if not dt.tzinfo:
dt = LOCAL_TZ.localize(dt)
dt = dt.astimezone(pytz.utc)
return dateformat.format(dt, format)
@register.filter(name='gpsdate')
def gpsdate(gpstime, format=FORMAT):
return dateformat.format(gpsToUTC(gpstime), format)
# GPS time conversion
# This is kind of awful in that leapSeconds
# are hard coded and needs to be kept up to date.
# Also, this should be somewhere else.
import calendar, datetime
gpsEpoch = calendar.timegm((1980, 1, 6, 0, 0, 0, 0, 0, 0))
leapSeconds = map(calendar.timegm, [
(1981, 7, 0, 0, 0, 0, 0, 0, 0),
(1982, 7, 0, 0, 0, 0, 0, 0, 0),
(1983, 7, 0, 0, 0, 0, 0, 0, 0),
(1985, 7, 0, 0, 0, 0, 0, 0, 0),
(1988, 1, 0, 0, 0, 0, 0, 0, 0),
(1990, 1, 0, 0, 0, 0, 0, 0, 0),
(1991, 1, 0, 0, 0, 0, 0, 0, 0),
(1992, 7, 0, 0, 0, 0, 0, 0, 0),
(1993, 7, 0, 0, 0, 0, 0, 0, 0),
(1994, 7, 0, 0, 0, 0, 0, 0, 0),
(1996, 1, 0, 0, 0, 0, 0, 0, 0),
(1997, 7, 0, 0, 0, 0, 0, 0, 0),
(1999, 1, 0, 0, 0, 0, 0, 0, 0),
(2006, 1, 0, 0, 0, 0, 0, 0, 0),
(2009, 1, 0, 0, 0, 0, 0, 0, 0),
])
def gpsToPosixTime(gpsTime):
t = gpsEpoch + gpsTime
for leap in leapSeconds:
if t >= leap:
t = t - 1
return t
def gpsToUTC(gpsTime):
t = gpsToPosixTime(gpsTime)
return datetime.datetime.fromtimestamp(t, pytz.utc)
......@@ -39,7 +39,9 @@ DATABASE_PORT = '' # Set to empty string for default.
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
GRACE_DATETIME_FORMAT = 'Y-m-d H:i:s T'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
......@@ -104,9 +106,9 @@ TEMPLATE_DIRS = (
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'gracedb.gracedb',
)
......@@ -32,7 +32,9 @@ DATABASE_PORT = '' # Set to empty string for default.
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
GRACE_DATETIME_FORMAT = 'Y-m-d H:i:s T'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
......
{% load timeutil %}
<ul>
<li><a href="{{ obj.weburl }}">Data</a></li>
<li><a href="{{ obj.wikiurl }}">TWiki</a></li>
</ul>
Sumbmitter: {{ obj.submitter.name }}<br/>
Created: {{ obj.created }}
Created: {{ obj.created|utc }}
{% extends "base.html" %}
{% load timeutil %}
{% block title %}View {{ object.graceid }}{% endblock %}
{% block heading %}View {{ object.graceid }}{% endblock %}
......@@ -11,7 +12,8 @@
<tr><th>Group</th><td>{{ object.group.name }}</td></tr>
<tr><th>Type</th><td>{{ object.get_analysisType_display }}</td></tr>
{% if object.gpstime %}
<tr><th>GPS Time</th><td>{{ object.gpstime }}</td></tr>
<tr><th>GPS Time</th><td>
<span title="{{ object.gpstime|gpsdate }}">{{ object.gpstime }}</span></td></tr>
{% endif %}
<tr><th>Data</th><td>
<a href="{{ object.weburl }}">{{ object.weburl }}</a>
......@@ -20,7 +22,8 @@
<a href="{{ object.wikiurl }}">{{ object.wikiurl }}</a>
</td></tr>
<tr><th>Sumitter</th><td>{{ object.submitter.name }}</td></tr>
<tr><th>Created</th><td>{{ object.created }}</td></tr>
<tr><th>Created</th><td>{{ object.created|utc }}
</td></tr>
</table>
{% if object.eventlog_set.count %}
......@@ -34,7 +37,7 @@
</tr>
{% for log in object.eventlog_set.iterator %}
<tr class={% cycle 'odd' 'even' %}>
<td>{{ log.created }}</td>
<td>{{ log.created|utc }}</td>
<td>{{ log.issuer }}</td>
<td><a href="{{ log.fileurl }}">{{ log.filename }}</a></td>
<td>{{ log.comment }}</td>
......
{% extends "base.html" %}
{% load timeutil %}
{% block title %}{{ title }}{% endblock %}
{% block heading %}{{ title }}{% endblock %}
......@@ -47,7 +48,9 @@
<td>{{ obj.submitter }} </td>
<td>{{ obj.group }} </td>
<td>{{ obj.get_analysisType_display }} </td>
<td>{% if obj.gpstime%}{{ obj.gpstime }}{% endif %}</td>
<td>{% if obj.gpstime%}
<span title="{{ obj.gpstime|gpsdate }}">{{ obj.gpstime }}</span>
{% endif %}</td>
<td><a href="{{ obj.weburl }}">Web: {{ obj.graceid }}</a></td>
<td><a href="{{ obj.wikiurl }}">Wiki: {{ obj.graceid }}</a></td>
</tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment