import re
from datetime import datetime


def match_to_datestamp(match: re.Match) -> datetime:
    """Helper function to convert match to a datetime object
    |   match object must have 7 groups where 
    |   group 0 is year
    |   group 1 is month
    |   group 2 is day
    |   group 3 is hour
    |   group 4 is minute
    |   group 5 is second
    |   group 6 is millisecond"""
    groups = [int(elm) for elm in match.groups()]
    try:
        assert len(groups) == 7
    except AssertionError:
        print("Match object may be in wrong format check the regular expression used.")
        raise AssertionError
    date = groups[:3] 
    time = groups[3:-1]
    microseconds = groups[-1]*1000 #convert millisecond to microsecond for datetime
    return datetime(date[0], date[1], date[2], hour = time[0], 
        minute = time[1], second = time[2], microsecond=microseconds)