11from typing import Optional
22import aiohttp
3- from datetime import datetime , timezone
3+ from datetime import datetime
44from 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