def string_time_from_ms(time_in_ms: int, hours: bool = False) -> str:
    """
    Convert timestamp in millisecond in a string with the format mm:ss.xxx
    If hours is true the format will be hh:mm:ss.xx
    """

    # if no time time_in_ms is equal to the maximum value of a 32bit int
    if time_in_ms == 2147483647 or time_in_ms == 65_535_000:
        # simply return 00:00.000
        time_in_ms = 0

    elif time_in_ms < 0:
        time_in_ms = 0

    if hours:
        hour = time_in_ms // 3_600_000
        minute = (time_in_ms % 3_600_000) // 60_000
        second = ((time_in_ms % 3_600_000) % 60_000) // 1_000
        millisecond = (((time_in_ms % 3_600_000) % 60_000) % 1_000)

    else:
        hour = 0
        minute = time_in_ms // 60_000
        second = (time_in_ms % 60_000) // 1_000
        millisecond = (time_in_ms % 60_000) % 1_000

    if hour < 10:
        hour_str = f"0{hour}"

    else:
        hour_str = str(hour)

    if minute < 10:
        minute_str = f"0{minute}"

    else:
        minute_str = str(minute)

    if second < 10:
        second_str = f"0{second}"

    else:
        second_str = str(second)

    if 10 < millisecond < 100:
        millisecond_str = f"0{millisecond}"

    elif millisecond < 10:
        millisecond_str = f"00{millisecond}"

    else:
        millisecond_str = str(millisecond)

    if hours:
        return f"{hour_str}:{minute_str}:{second_str}.{millisecond_str}"

    else:
        return f"{minute_str}:{second_str}.{millisecond_str}"