Spaces:
Runtime error
Runtime error
File size: 651 Bytes
a030e94 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import re
from datetime import datetime
def get_duration_in_seconds(text: str) -> int:
parts = list(map(int, text.strip().split(":")))
if len(parts) == 2:
minutes, seconds = parts
return minutes * 60 + seconds
elif len(parts) == 3:
hours, minutes, seconds = parts
return hours * 3600 + minutes * 60 + seconds
return 0
def parse_year_from_text(texts):
now = datetime.now().year
for text in texts:
if "year" in text:
m = re.search(r"(\d+)", text)
if m:
return now - int(m.group(1))
elif "month" in text:
return now
return 0 |