def datetime_to_iso_8601(dt):
    """Format a datetime as an iso 8601 string - YYYY-MM-DDTHH:MM:SS with optional timezone +HH:MM."""
    if dt:
        return dt.replace(microsecond=0).isoformat()
    else:
        return None