from datetime import datetime


def last_checked_date(in_layer):
    """Checks the last time the GISSCR user created floodplain delineations in
    the city's floodplains in order to approximate the last time the script
    was run.

    Parameters
    ----------
    in_layer : FeatureLayer
        An arcgis feature layer

    Returns
    -------
    str
        The last date the layer was edited by the GISSCR user (e.g. 2019-04-01)
    """
    where = ("CREATED_USER = 'GISSCR' AND (FLOODZONE LIKE 'A%' OR FLOODZONE "
             "IN ('X', 'B'))")
    query = in_layer.query(out_fields=["CREATED_USER", "CREATED_DATE"],
                           where=where,
                           return_geometry=False)
    ts = max([f.attributes["CREATED_DATE"] for f in query.features])/1000
    formatted = datetime.fromtimestamp(ts).strftime("%Y-%m-%d")
    return formatted