def regularise_periapse_time(raw, period):

    """
    Change the periapse time so it would be between 0 and the period
    """

    res = raw
    if res < 0:
        res += period
    if res > period:
        res -= period
    return res