about summary refs log tree commit diff stats
path: root/modules/by-name
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-04 22:36:33 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-04 22:36:33 +0200
commit8117fe3df4cb647d66abeb3e86c1bd220b1fa650 (patch)
tree482ae1ebfcc14ddd06521ff4e0b29bb35b14a152 /modules/by-name
parentfix(modules/timewarrior): Fix type in `hooks` directory (diff)
downloadnixos-config-8117fe3df4cb647d66abeb3e86c1bd220b1fa650.zip
fix(modules/timewarrior/hooks/track-total-active-time): Move dateparsing to datetime
Diffstat (limited to '')
-rwxr-xr-xmodules/by-name/ti/timewarrior/taskwarrior_hooks/on-modify.track-total-active-time.py30
1 files changed, 1 insertions, 29 deletions
diff --git a/modules/by-name/ti/timewarrior/taskwarrior_hooks/on-modify.track-total-active-time.py b/modules/by-name/ti/timewarrior/taskwarrior_hooks/on-modify.track-total-active-time.py
index b98e02fc..0b6be082 100755
--- a/modules/by-name/ti/timewarrior/taskwarrior_hooks/on-modify.track-total-active-time.py
+++ b/modules/by-name/ti/timewarrior/taskwarrior_hooks/on-modify.track-total-active-time.py
@@ -30,7 +30,6 @@ This hook is a fork from `kostajh/taskwarrior-time-tracking-hook`_
 
 import datetime
 import json
-import re
 import sys
 import subprocess
 from typing import TypeVar
@@ -40,9 +39,6 @@ UDA_KEY = "total_active_time"
 
 MAX_ACTIVE = 1
 
-"""Compiled regular expression for the duration as ISO-8601 formatted string."""
-ISO8601DURATION = re.compile("P((\d*)Y)?((\d*)M)?((\d*)D)?T((\d*)H)?((\d*)M)?((\d*)S)?")
-
 """The duration type either as integer (in seconds), as ISO-8601 formatted string ("PT1H10M31S") or the seconds suffixed with "seconds"."""
 DurationType = TypeVar("DurationType", str, int)
 
@@ -54,31 +50,7 @@ def duration_str_to_time_delta(duration_str: DurationType) -> datetime.timedelta
     :return: The duration as timedelta object
     """
     if duration_str.startswith("P"):
-        match = ISO8601DURATION.match(duration_str)
-        if match:
-            year = match.group(2)
-            month = match.group(4)
-            day = match.group(6)
-            hour = match.group(8)
-            minute = match.group(10)
-            second = match.group(12)
-            value = 0
-            if second:
-                value += int(second)
-            if minute:
-                value += int(minute) * 60
-            if hour:
-                value += int(hour) * 3600
-            if day:
-                value += int(day) * 3600 * 24
-            if month:
-                # Assume a month is 30 days for now.
-                value += int(month) * 3600 * 24 * 30
-            if year:
-                # Assume a year is 365 days for now.
-                value += int(year) * 3600 * 24 * 365
-        else:
-            value = int(duration_str)
+        value = datetime.fromisoformat(duration_str)
     elif duration_str.endswith("seconds"):
         value = int(duration_str.rstrip("seconds"))
     else: