passing tests
This commit is contained in:
@@ -26,6 +26,11 @@ import requests
|
||||
from django.http import HttpResponse
|
||||
|
||||
import humanize
|
||||
from pytz.exceptions import UnknownTimeZoneError
|
||||
import pytz
|
||||
import iso8601
|
||||
from iso8601 import ParseError
|
||||
import arrow
|
||||
|
||||
lbstoN = 4.44822
|
||||
|
||||
@@ -1232,3 +1237,37 @@ def intervals_to_string(vals, units, typ):
|
||||
s = s[1:]
|
||||
|
||||
return s
|
||||
|
||||
def get_timezone_from_c2data(data):
|
||||
|
||||
try:
|
||||
timezone = pytz.timezone(data['timezone'])
|
||||
except UnknownTimeZoneError:
|
||||
timezone = pytz.utc
|
||||
except KeyError:
|
||||
timezone = pytz.utc
|
||||
|
||||
return timezone
|
||||
|
||||
|
||||
def get_startdatetime_from_c2data(data):
|
||||
timezone = get_timezone_from_c2data(data)
|
||||
try:
|
||||
startdatetime = iso8601.parse_date(data['date_utc'])
|
||||
except: # pragma: no cover
|
||||
startdatetime = iso8601.parse_date(data['date'])
|
||||
|
||||
totaltime = data['time']/10.
|
||||
duration = totaltime_sec_to_string(totaltime)
|
||||
starttimeunix = arrow.get(startdatetime).timestamp()-totaltime
|
||||
startdatetime = arrow.get(starttimeunix)
|
||||
startdatetime = startdatetime.astimezone(timezone)
|
||||
|
||||
workoutdate = startdatetime.astimezone(
|
||||
timezone
|
||||
).strftime('%Y-%m-%d')
|
||||
starttime = startdatetime.astimezone(
|
||||
timezone
|
||||
).strftime('%H:%M:%S')
|
||||
|
||||
return startdatetime,starttime,workoutdate,duration,starttimeunix,timezone
|
||||
|
||||
Reference in New Issue
Block a user