def calc_last_time_active(xml_element, filename):
    """
    Calculate the absolute time (in EPOCH) when an event was active for the last time.
    :param xml_element: The element containing an lastTimeActive attribute
    :param filename: A filename where the name contains digits only, representing the creation time in EPOCH.
    :return: The EPOCH representation of the time an event was active for the last time.
    """
    if 'lastTimeActive' in xml_element.keys():
        relative_last_time_active = int(xml_element.attrib['lastTimeActive'])

        # Some events show the last_time_active as EPOCH already, which is indicated by starting with a minus sign
        if relative_last_time_active < 0:
            last_time_active = abs(relative_last_time_active)

        # Otherwise we need to add the filename (which is the start time in EPOCH)
        # to the relative time (represented in ms)
        else:
            last_time_active = int(filename) + relative_last_time_active
        # time from ms to s since epoch
        return last_time_active/1000