Skip to content

Instantly share code, notes, and snippets.

@CharlieRa
Created August 21, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlieRa/4e455605511a37c27e73 to your computer and use it in GitHub Desktop.
Save CharlieRa/4e455605511a37c27e73 to your computer and use it in GitHub Desktop.
Script que convierte una fecha de GPS con epoch del 6 de Enero de 1980 a GMT 0 y GMT -3 de Santiago de Chile
#!/usr/bin/python
# Usage: python convert.py <gpsDate> - ej formato: 1858349648
import datetime
import sys
# 1858 3 49648
def convert(gpsDate):
epochDate = datetime.datetime.strptime("1980-1-6 00:00:00","%Y-%m-%d %H:%M:%S")
# print epochDate
week = gpsDate[0:4]
days = gpsDate[4:5]
seconds = gpsDate[5:]
# print "semanas:"+week+" dias: "+days+" segundos: "+seconds
addDays=(int(week)*7)+int(days)
d = datetime.timedelta(days=int(addDays))
epochDate = epochDate + d
gmt = epochDate + datetime.timedelta(seconds=int(seconds))
gmtSantiago = gmt - datetime.timedelta(seconds=int(10800))
print "GMT 0: "+str(gmt)
print "GMT-3: "+str(gmtSantiago)
return "--------------------------"
if __name__ == "__main__":
try:
val = int(sys.argv[1])
print convert(sys.argv[1])
except ValueError:
print("Ingrese solo numero enteros positivos")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment