import math


def weeks_to_sample(time_steps):
    """
    Calculates the weeks to sample for a GMM model based on the time steps of the simulation.

    Args:
        time_steps: (list): Contains time_steps in `datetime.datetime` format

    Returns:
        num_weeks: (int): # weeks to sample
    """
    # Total duration of simulation period in hours
    last = time_steps[-1]
    first = time_steps[0]
    total_hours = (last - first).total_seconds() / 3600

    num_weeks = math.ceil(total_hours / 168)

    # If the first time stamp is later in the week add one week to sample
    if first.weekday() > last.weekday():
        num_weeks += 1
    elif first.weekday() == last.weekday():
        if first.time() > last.time():
            num_weeks += 1

    return num_weeks