import csv


def write_proc_periods(start_times, end_times, fname):
    """
    writes an output file containing start and stop times of periods to
    process

    Parameters
    ----------
    start_times, end_times : datetime object
        The starting and ending times of the periods
    fname : str
        The name of the file where to write

    Returns
    -------
    fname : str
        the name of the file containing the content

    """
    with open(fname, 'w', newline='') as csvfile:
        field_names = ['start_time', 'end_time']
        writer = csv.DictWriter(csvfile, field_names)
        writer.writeheader()

        for start_time, end_time in zip(start_times, end_times):
            dict_row = {
                'start_time': start_time.strftime('%Y%m%d%H%M%S'),
                'end_time': end_time.strftime('%Y%m%d%H%M%S')
            }
            writer.writerow(dict_row)
        csvfile.close()

    return fname