From bd81fa89137feb9895eb82bc43722ce933f468b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Bu=C3=9Fmann?= Date: Thu, 20 Jun 2024 00:20:25 +0200 Subject: [PATCH] as toggl -> reclaim sync is based on today it was made tz local aware --- things2reclaim/main.py | 9 +++++++-- things2reclaim/reclaim_handler.py | 2 +- things2reclaim/toggl_handler.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/things2reclaim/main.py b/things2reclaim/main.py index 87262be..69f2295 100755 --- a/things2reclaim/main.py +++ b/things2reclaim/main.py @@ -1,7 +1,7 @@ #!/opt/homebrew/Caskroom/miniconda/base/envs/things-automation/bin/python3 import sqlite3 -from datetime import datetime, timedelta +from datetime import datetime from pathlib import Path from typing import Dict, List, Optional, Union import tomllib @@ -334,6 +334,9 @@ def sync_toggl_reclaim_tracking(): since_days = 0 reclaim_handler.get_reclaim_tasks() toggl_time_entries = toggl_handler.get_time_entries_since(since_days = since_days) # end date is inclusive + if toggl_time_entries is None: + utils.pwarning("No tasks tracked today in Toggl") + return reclaim_time_entries = reclaim_handler.get_task_events_since(since_days = since_days) # end date is inclusive reclaim_time_entry_names = [reclaim_handler.get_clean_time_entry_name(time_entry.name) for time_entry in reclaim_time_entries] missing_reclaim_entries = [time_entry for time_entry in toggl_time_entries if time_entry.description not in reclaim_time_entry_names] @@ -363,7 +366,9 @@ def display_current_task(): if current_task is None: utils.perror("No task is currently tracked in toggl") return - rprint(f"Current task: {current_task.description}\nStarted at: {current_task.start.astimezone(tz.gettz()).strftime("%H:%M")}") + rprint((f"Current task: {current_task.description}\nStarted at:", + f"{toggl_handler.get_start_time(current_task) + .astimezone(tz.gettz()).strftime("%H:%M")}")) @app.command("sync") diff --git a/things2reclaim/reclaim_handler.py b/things2reclaim/reclaim_handler.py index fbaa3bb..9cb70ed 100644 --- a/things2reclaim/reclaim_handler.py +++ b/things2reclaim/reclaim_handler.py @@ -75,7 +75,7 @@ def is_task_time_entry(name: str): def get_task_events_since(since_days: int = 0) -> List[ReclaimTaskEvent]: - date_now = datetime.now(tz.tzutc()).date() + date_now = datetime.now(tz.tzlocal()).date() date_since = date_now - timedelta(days=since_days) date_end = date_now + timedelta(days = 1) # end date is exclusive events = ReclaimTaskEvent.search(date_since, date_end) diff --git a/things2reclaim/toggl_handler.py b/things2reclaim/toggl_handler.py index 969a195..f8917a4 100644 --- a/things2reclaim/toggl_handler.py +++ b/things2reclaim/toggl_handler.py @@ -56,7 +56,7 @@ def get_time_entries_since(since_days: int = 30) -> List[toggl_python.TimeEntry] """ if since_days > 90: raise ValueError("since_days can't be more than 90 days") - midnight = datetime.combine(datetime.now(), time.min) + midnight = datetime.combine(datetime.now(tz.tzlocal()), time.min) time_stamp = int((midnight - timedelta(days=since_days)).timestamp()) return toggl_python.TimeEntries(auth=auth).list(since=time_stamp)