def dates_to_fits(date_begin, date_end):
    """Convert two dates into FITS form.

    Parameters
    ----------
    date_begin : `astropy.time.Time`
        Date representing the beginning of the observation.
    date_end  : `astropy.time.Time`
        Date representing the end of the observation.

    Returns
    -------
    cards : `dict` of `str` to `str` or `float`
        Header card keys and values following the FITS standard.
        If neither date is defined this may be empty.
    """
    cards = {}
    if date_begin is None and date_end is None:
        # no date headers can be written
        return cards

    cards["TIMESYS"] = "TAI"

    date_avg = None
    if date_begin is not None and date_end is not None:
        date_avg = date_begin + (date_end - date_begin)/2.0

    for fragment, date in (("OBS", date_begin), ("END", date_end), ("AVG", date_avg)):
        if date is not None:
            tai = date.tai
            cards[f"DATE-{fragment}"] = tai.isot
            cards[f"MJD-{fragment}"] = tai.mjd

    return cards