import math


def generate_timecode(ms: int) -> str:
    """
    Convert a duration in seconds to ISO8601 hh:mm:ss.sss format
    """
    hours = math.floor(ms / (60 * 60 * 1000))
    minutes = math.floor(ms / (60 * 1000)) % 60
    seconds = math.floor(ms / 1000) % 60
    milliseconds = ms % 1000
    return (
        str(hours).rjust(2, "0")
        + ":"
        + str(minutes).rjust(2, "0")
        + ":"
        + str(seconds).rjust(2, "0")
        + "."
        + str(milliseconds).rjust(3, "0")
    )