I have a program that is supposed to keep a running total of time spent doing something. I have a value stored, that is meant to start at "000d 00h 00m 00s" for 0 days, hours, minutes, and seconds. However, if I try to add a time to it, I receive "ValueError: time data '000d 00h 00m 00s' does not match format '%jd %Hh %Mm %Ss'".
If I change the starting string to '001d 00h 00m 00s' it will add the time no problem, but then I will have a value 24 hours greater than what is accurate. It will also function if I just remove the day counter and have it '00h 00m 00s', but it will then still reset the hours once it hits 24.
Being able to start at '000d 00h 00m 00s' would be preferable, but if that isn't possible, having the hours overflow (i.e. "25h 00m 00s') would work.
from datetime import *
EmptyTime = '000d 00h 00m 00s'
EmptyTimeThatWorks = '001d 00h 00m 00s'
ExampleTime = '174d 19h 07m 53s' # June 23 7:07 PM
FMT = "%jd %Hh %Mm %Ss"
def TaskEnded(RunningTotal, TimerStartTime):
PresentTime = datetime.now().strftime(FMT) #PresnetTime is when the TaskEnded
st = datetime.strptime(TimerStartTime, FMT) #Brings things into the right format
pt = datetime.strptime(PresentTime, FMT) #Brings things into the right format
rt = datetime.strptime(RunningTotal, FMT) #Brings things into the right format, but EmptyTime cant be
# conveted to the right time because day '0' doenst exist
# while hour, minute, and second 0 do
NewTotal = rt + (pt - st) #takes the running total and adds the timer value, which is the difference of start and end times
NewTotal2 = datetime.strftime(NewTotal, FMT) # Puts the Datetime value back into the right format FMT
print(NewTotal2)
return NewTotal2
TaskEnded(EmptyTimeThatWorks, ExampleTime)
TaskEnded(EmptyTime, ExampleTime)