more fixes for ms thing, please rewrite this in a way that makes more sense if you have time lol

This commit is contained in:
DESKTOP-5A96VAJ\Julian
2024-12-15 23:00:32 -05:00
committed by Mc-muffin
parent 7b748ffcb2
commit 101d8ea4a1

View File

@@ -23,19 +23,25 @@ rTIME_STAMP_NO_HOUR = r"(\d+):(\d+)[.,](\d+)"
def str_to_timestamp(time_stamp: str) -> TimeStamp:
colon_cnt = time_stamp.count(":")
if colon_cnt == 2:
times = [int(s) for s in re.findall(rTIME_STAMP, time_stamp)[0]]
hours = times[0]
minutes = times[1]
seconds = times[2]
milis = times[3]
milis = int(str(milis).ljust(3, '0'))
if colon_cnt == 1:
times = [int(s) for s in re.findall(rTIME_STAMP_NO_HOUR, time_stamp)[0]]
hours = 0
minutes = times[0]
seconds = times[1]
milis = times[2]
milis = int(str(milis).ljust(3, '0'))
# For HH:MM:SS.mmm
times = re.findall(rTIME_STAMP, time_stamp)
if times:
hours, minutes, seconds, milis_str = times[0]
hours, minutes, seconds = map(int, (hours, minutes, seconds))
milis = int((milis_str + "000")[:3]) # Normalize to 3 digits
else:
raise ValueError("Invalid time_stamp format for HH:MM:SS.mmm")
elif colon_cnt == 1:
# For MM:SS.mmm
times = re.findall(rTIME_STAMP_NO_HOUR, time_stamp)
if times:
minutes, seconds, milis_str = times[0]
minutes, seconds = map(int, (minutes, seconds))
milis = int((milis_str + "000")[:3]) # Normalize to 3 digits
hours = 0
else:
raise ValueError("Invalid time_stamp format for MM:SS.mmm")
if colon_cnt == 0 or time_stamp.isspace():
hours = 0
minutes = 0