feat: add initial support for positioning

Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
Konstantin Fickel 2025-06-22 18:02:42 +02:00
parent 28dc40ebf0
commit 0c61067db0
Signed by: kfickel
GPG key ID: A793722F9933C1A5
9 changed files with 186 additions and 3 deletions

View file

@ -0,0 +1,21 @@
from datetime import datetime
import re
import os
from typing import Optional
def extract_date_from_file_name(file_name: str) -> Optional[datetime]:
FILE_NAME_REGEX = r"^(?P<date>\d{8})(?:-(?P<time>\d{4,6}))?.+.md$"
base_name = os.path.basename(file_name)
match = re.match(FILE_NAME_REGEX, base_name)
if match:
date_str = match.group("date")
time_str = match.group("time") or ""
time_str = time_str.ljust(6, "0")
datetime_str = f"{date_str} {time_str[:2]}:{time_str[2:4]}:{time_str[4:]}"
return datetime.strptime(datetime_str, "%Y%m%d %H:%M:%S")
return None
__all__ = ["extract_date_from_file_name"]