def get_certificates_with_same_cn_with_rotate_on(cn, date_created):
    """
    Find certificates with given common name created on date_created that are still valid, not replaced and marked for
    auto-rotate

    :param cn: common name to match
    :param date_created: creation date
    :return: List of certificates matching the criteria
    """
    now = arrow.now().format("YYYY-MM-DD")
    date_created_min = date_created.floor('day')
    date_created_max = date_created.ceil('day')

    query = database.session_query(Certificate)\
        .filter(Certificate.rotation == true())\
        .filter(Certificate.not_after >= now)\
        .filter(Certificate.date_created >= date_created_min)\
        .filter(Certificate.date_created <= date_created_max)\
        .filter(not_(Certificate.replaced.any()))

    if cn is not None:
        query = query.filter(Certificate.cn.like(cn))
    else:
        query = query.filter(Certificate.cn.is_(None))

    return query.all()

    Find certificates with given common name created on date_created that are still valid, not replaced and marked for
    auto-rotate

    :param cn: common name to match
    :param date_created: creation date
    :return: List of certificates matching the criteria
    
lemur/certificates/service.py