Skip to content

Commit afe5410

Browse files
committed
fix the date in stop and start tracking api
1 parent 65137ef commit afe5410

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/task_tracker/api/trackingtime_client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22
import aiohttp
3-
from datetime import datetime, timezone
3+
from datetime import datetime
44
from task_tracker.config import settings
55

66

@@ -21,16 +21,18 @@ async def start_tracking(self, project: str, description: str) -> dict:
2121
Returns:
2222
dict: json containing the tracking_task_id
2323
"""
24-
async with aiohttp.ClientSession(auth=self.auth, headers=self.headers) as session:
25-
current_time = datetime.now(
26-
timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
24+
async with aiohttp.ClientSession(auth=self.auth) as session:
25+
# Get local time
26+
local_tz = datetime.now().astimezone().tzinfo
27+
current_time = datetime.now(local_tz).strftime("%Y-%m-%d %H:%M:%S")
28+
2729
async with session.post(
2830
f"{self.base_url}/tasks/track",
2931
params={
3032
"date": current_time,
3133
"task_name": description,
3234
"project_name": project,
33-
"return_task": "true"
35+
"return_task": "true",
3436
}
3537
) as response:
3638
response.raise_for_status()
@@ -47,8 +49,10 @@ async def stop_tracking(self, task_id: str) -> dict:
4749
dict: Response from TrackingTime API containing the task details
4850
"""
4951
async with aiohttp.ClientSession(auth=self.auth, headers=self.headers) as session:
50-
current_time = datetime.now(
51-
timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
52+
# stop and start timezone must match, otherwise server 500
53+
local_tz = datetime.now().astimezone().tzinfo
54+
current_time = datetime.now(local_tz).strftime("%Y-%m-%d %H:%M:%S")
55+
5256
async with session.post(
5357
f"{self.base_url}/tasks/stop",
5458
params={

0 commit comments

Comments
 (0)