import math


def _datetime_to_timestamp(dt, period, round_up=False):
    """ Convert a datetime object to a timestamp measured in simulation periods.

    Args:
        dt (datetime): Datetime to be converted to a simulation timestamp.
        period (int): Length of one time interval in the simulation. (minutes)
        round_up (bool): If True, round up when casting timestamp to int, else round down.

    Returns:
        int: dt expressed as a simulation timestamp.
    """
    ts = dt.timestamp() / (60 * period)
    if round_up:
        return int(math.ceil(ts))
    else:
        return int(ts)