Created
January 6, 2015 17:13
-
-
Save jeremiahajohnson/7299e099a6cbc88fac0a to your computer and use it in GitHub Desktop.
Local time to GPS Week and GPS Seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def localtogps(timestring,timeformat,leapseconds,localoffset=0): | |
import datetime | |
epoch = datetime.datetime.strptime("1980-01-07 00:00:00","%Y-%m-%d %H:%M:%S") | |
local = datetime.datetime.strptime(timestring,timeformat) | |
utc = local - datetime.timedelta(hours=localoffset) | |
diff = utc-epoch | |
gpsWeek = diff.days/7 | |
secondsThroughDay = (utc.hour * 3600) + (utc.minute * 60) + utc.second | |
if utc.isoweekday()== 7: | |
weekday = 0 | |
else: | |
weekday = utc.isoweekday() | |
gpsSeconds = (weekday * 86400) + secondsThroughDay - leapseconds | |
return (gpsWeek,gpsSeconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment