From 99b4d47e3cc14c4cd35626db549d17282331df95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Melan=C3=A7on?= Date: Sun, 12 Dec 2021 12:19:07 -0500 Subject: [PATCH] proof of concept shifting date --- pomodoro_to_harvest.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pomodoro_to_harvest.py b/pomodoro_to_harvest.py index af3ee98..6363c7f 100644 --- a/pomodoro_to_harvest.py +++ b/pomodoro_to_harvest.py @@ -89,6 +89,23 @@ timelog['description'] = (np.where(timelog['description'].str.contains(': '), ti timelog['description'] = timelog['description'].str.strip() timelog['project'] = timelog['project'].str.strip() +timelog['tmp_timeshift'] = timelog['description'].str.extract(r'^(\(.+)\)', expand=False) +timelog['tmp_timeshift'] = timelog['tmp_timeshift'].str.strip().str.replace("(","") +# In an ideal world we would use https://github.com/bear/parsedatetime or similar and +# even better figure out the right date for strings like "Monday" but eh this'll do. +timeshift_days = { + -1: ['one day ago', '1 day ago', 'yesterday'], + -2: ['two days ago', '2 days ago', 'day before yesterday', 'the day before yesterday'], + -3: ['three days ago', '3 days ago'], + -4: ['four days ago', '4 days ago'], + -5: ['five days ago', '5 days ago'], +} +for days, phrases in timeshift_days.items(): + phrases.append(str(days)) + timelog.loc[timelog.tmp_timeshift.str.lower().isin(phrases), "tmp_daysdelta"] = int(days) +timelog['tmp_daysdelta'] = timelog['tmp_daysdelta'].fillna(0) +timelog['date'] = timelog['date'] + pd.to_timedelta(timelog['tmp_daysdelta'], unit='D') + # If a multiplier has been provided (an asterisk and an integer at the end of a # task), then multiply the time by it and remove it from the description. # Ensure we're splitting on the same asterisk we found: Use the end of string