time zone stuff correction
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
|
||||
from rowers.imports import *
|
||||
import datetime
|
||||
|
||||
import requests
|
||||
from requests_oauthlib import OAuth1,OAuth1Session
|
||||
from requests import Request, Session
|
||||
@@ -18,6 +19,8 @@ from rowsandall_app.settings import (
|
||||
GARMIN_CLIENT_KEY, GARMIN_REDIRECT_URI, GARMIN_CLIENT_SECRET
|
||||
)
|
||||
|
||||
from pytz import timezone as tz, utc
|
||||
|
||||
from rowers.tasks import handle_c2_import_stroke_data, handle_c2_sync
|
||||
import django_rq
|
||||
queue = django_rq.get_queue('default')
|
||||
@@ -128,6 +131,11 @@ def get_garmin_workout_list(user):
|
||||
def garmin_getworkout(garminid,r,activity):
|
||||
starttime = activity['startTimeInSeconds']
|
||||
startdatetime = arrow.get(starttime)
|
||||
try:
|
||||
offset = activity['startTimeOffsetInSeconds']
|
||||
except KeyError:
|
||||
offset = 0
|
||||
print(offset)
|
||||
durationseconds = activity['durationInSeconds']
|
||||
duration = dataprep.totaltime_sec_to_string(durationseconds)
|
||||
activitytype = activity['activityType']
|
||||
@@ -148,15 +156,29 @@ def garmin_getworkout(garminid,r,activity):
|
||||
except Workout.DoesNotExist:
|
||||
newcsvfile='media/garmin{code}_{importid}.csv'
|
||||
w = Workout(user=r,csvfilename=newcsvfile)
|
||||
w.startdatetime = datetime.datetime(
|
||||
|
||||
utc_offset = datetime.timedelta(seconds=offset)
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
zones = [tz.zone for tz in map(pytz.timezone, pytz.all_timezones_set)
|
||||
if now.astimezone(tz).utcoffset() == utc_offset]
|
||||
if r.defaulttimezone in zones:
|
||||
thetimezone = r.defaulttimezone
|
||||
elif len(zones):
|
||||
thetimezone = zones[0]
|
||||
else:
|
||||
thetimezone = utc
|
||||
|
||||
startdatetime = datetime.datetime(
|
||||
year=startdatetime.year,
|
||||
month=startdatetime.month,
|
||||
day=startdatetime.day,
|
||||
hour=startdatetime.hour,
|
||||
minute=startdatetime.minute,
|
||||
second=startdatetime.second,
|
||||
tzinfo=startdatetime.tzinfo)
|
||||
w.starttime = startdatetime.time()
|
||||
).astimezone(pytz.timezone(thetimezone))
|
||||
|
||||
w.startdatetime = startdatetime
|
||||
w.starttime = w.startdatetime.time()
|
||||
try:
|
||||
w.duration = datetime.datetime.strptime(duration,"%H:%M:%S.%f").time()
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user