Skip to content

Commit 3eee5b3

Browse files
committed
set local timezone
1 parent 214009b commit 3eee5b3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

roboflow/adapters/deploymentapi.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,25 @@ def list_deployment(api_key):
4444

4545

4646
def get_workspace_usage(api_key, from_timestamp, to_timestamp):
47-
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_workspace?api_key={api_key}&from_timestamp={from_timestamp.isoformat()}&to_timestamp={to_timestamp.isoformat()}"
47+
params = {"api_key": api_key}
48+
if from_timestamp is not None:
49+
params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign
50+
if to_timestamp is not None:
51+
params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign
52+
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_workspace?{urllib.parse.urlencode(params)}"
4853
response = requests.get(url)
4954
if response.status_code != 200:
5055
return response.status_code, response.text
5156
return response.status_code, response.json()
5257

5358

5459
def get_deployment_usage(api_key, deployment_name, from_timestamp, to_timestamp):
55-
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_deployment?api_key={api_key}&deployment_name={deployment_name}&from_timestamp={from_timestamp.isoformat()}&to_timestamp={to_timestamp.isoformat()}"
60+
params = {"api_key": api_key, "deployment_name": deployment_name}
61+
if from_timestamp is not None:
62+
params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign
63+
if to_timestamp is not None:
64+
params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign
65+
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_deployment?{urllib.parse.urlencode(params)}"
5666
response = requests.get(url)
5767
if response.status_code != 200:
5868
return response.status_code, response.text

roboflow/deployment.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ def check_from_to_timestamp(from_timestamp, to_timestamp, default_timedelta):
2323
print("Please provide a valid to_timestamp in ISO8601 format")
2424
exit(1)
2525

26-
time_now = datetime.now().replace(tzinfo=None)
26+
time_now = datetime.now().astimezone() # local timezone
2727
if from_timestamp is None and to_timestamp is None:
2828
from_timestamp = time_now - default_timedelta
2929
to_timestamp = time_now
3030
elif from_timestamp is not None and to_timestamp is None:
31-
from_timestamp = datetime.fromisoformat(from_timestamp).replace(tzinfo=None)
31+
from_timestamp = datetime.fromisoformat(from_timestamp).astimezone()
3232
to_timestamp = from_timestamp + default_timedelta
3333
elif from_timestamp is None and to_timestamp is not None:
34-
to_timestamp = datetime.fromisoformat(to_timestamp).replace(tzinfo=None)
34+
to_timestamp = datetime.fromisoformat(to_timestamp).astimezone()
3535
from_timestamp = to_timestamp - default_timedelta
3636
else:
37-
from_timestamp = datetime.fromisoformat(from_timestamp).replace(tzinfo=None)
38-
to_timestamp = datetime.fromisoformat(to_timestamp).replace(tzinfo=None)
37+
from_timestamp = datetime.fromisoformat(from_timestamp).astimezone()
38+
to_timestamp = datetime.fromisoformat(to_timestamp).astimezone()
3939
if from_timestamp >= to_timestamp:
4040
print("from_timestamp should be earlier than to_timestamp")
4141
exit(1)

0 commit comments

Comments
 (0)