def firstdate(time_mod, time_obs):
    """Gives the first common date of time_mod and time_obs
    WARNING : Use only sorted time series with datetime / Timestamp objects

    Parameters:
    ----------
    * time_mod : (pd.Series of dates)
        Series giving the dates of modeled values (usually)
        ex: 2012-02-01 10:00:00   2012-02-01 10:00:00
            2012-02-01 11:30:00   2012-02-01 11:30:00
            ...
    * time_obs : (pd.Series of dates)
        Series giving the dates of observed values (usually)

    Outputs:
    -------
    * starting_date0 : (datetime) first date of time_mod in the intersection
    * starting_date1 : (datetime) first date of time_obs in the intersection
    * i0 : (int) index of the first date of time_mod in the intersection
    * i1 : (int) index of the first date of time_obs in the intersection
    """
    reversed = False
    if time_mod[0] > time_obs[0]:
        reversed = True
        time_mod, time_obs = time_obs, time_mod
    i = 0
    while time_mod[i] < time_obs[0] and i < len(time_mod) - 1:
        print(time_mod[i] < time_obs[0])
        i = i + 1
    eq = time_mod[i] == time_obs[0]
    if not reversed and not eq:
        starting_date0 = time_mod[i - 1]
        i0 = i - 1
    else:
        starting_date0 = time_mod[i]
        i0 = i
    starting_date1 = time_obs[0]
    i1 = 0
    if starting_date0 == time_mod[len(time_mod) - 1] and not eq:
        starting_date0, starting_date1 = None, None
    if reversed is True:
        starting_date0, starting_date1 = starting_date1, starting_date0
        i0, i1 = i1, i0
    return starting_date0, starting_date1, i0, i1
