Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael William Coughlin
GraceDB Server
Commits
ad83ef8d
Commit
ad83ef8d
authored
15 years ago
by
Brian Moe
Browse files
Options
Downloads
Patches
Plain Diff
moved time utils out of template tags lib
parent
f33ca4cd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gracedb/models.py
+1
-1
1 addition, 1 deletion
gracedb/models.py
gracedb/templatetags/timeutil.py
+1
-52
1 addition, 52 deletions
gracedb/templatetags/timeutil.py
utils/__init__.py
+53
-0
53 additions, 0 deletions
utils/__init__.py
with
55 additions
and
53 deletions
gracedb/models.py
+
1
−
1
View file @
ad83ef8d
...
...
@@ -6,7 +6,7 @@ import os
from
gracedb.ligolw.models
import
CoincEvent
from
gracedb.
gracedb.templatetags.time
util
import
posixToGpsTime
from
gracedb.util
s
import
posixToGpsTime
from
django.conf
import
settings
import
pytz
,
time
...
...
This diff is collapsed.
Click to expand it.
gracedb/templatetags/timeutil.py
+
1
−
52
View file @
ad83ef8d
...
...
@@ -6,6 +6,7 @@ from django.utils import dateformat
from
django.utils.html
import
conditional_escape
from
django.utils.safestring
import
mark_safe
from
gracedb.utils
import
posixToGpsTime
,
gpsToUtc
import
pytz
import
time
...
...
@@ -114,55 +115,3 @@ def utc(dt, format=FORMAT):
def
gpsdate
(
gpstime
,
format
=
FORMAT
):
return
dateformat
.
format
(
gpsToUtc
(
gpstime
),
format
)
# TAG that generates stuff that changes time display what-nots.
# 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.
# Also, there are almost certainly failing edge cases at leap second adjustment times.
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
posixToGpsTime
(
posixTime
):
change
=
0
for
leap
in
leapSeconds
:
if
posixTime
>
leap
:
change
+=
1
return
posixTime
+
change
-
gpsEpoch
def
gpsToUtc
(
gpsTime
):
t
=
gpsToPosixTime
(
gpsTime
)
return
datetime
.
datetime
.
fromtimestamp
(
t
,
pytz
.
utc
)
This diff is collapsed.
Click to expand it.
utils/__init__.py
0 → 100644
+
53
−
0
View file @
ad83ef8d
# GPS time conversion
# This is kind of awful in that leapSeconds
# are hard coded and needs to be kept up to date.
# Also, this probably is/will be/should be in glue.
# Also, there are almost certainly failing edge cases at leap second adjustment times.
# Oh yea, and I don't think this works exactly right for some periods 2006-2008, say.
import
pytz
import
datetime
import
calendar
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
posixToGpsTime
(
posixTime
):
change
=
0
for
leap
in
leapSeconds
:
if
posixTime
>
leap
:
change
+=
1
return
posixTime
+
change
-
gpsEpoch
def
gpsToUtc
(
gpsTime
):
t
=
gpsToPosixTime
(
gpsTime
)
return
datetime
.
datetime
.
fromtimestamp
(
t
,
pytz
.
utc
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment