def get_isoduration(date_str):
    iso_duration = None

    if not date_str:
        return None

    #first, is it already a valid isoduration?
    try:
        isodate.parse_duration(date_str)
        return date_str
    except isodate.ISO8601Error, e:
        # if not, try to parse it
        try:
            delta = (timelib.strtodatetime(date_str) - timelib.strtodatetime('now'))
            iso_duration = isodate.duration_isoformat(delta)
        except Exception, e:
            log.msg(e.message, level=log.WARNING)
            return None

        return iso_duration
convert the given date_str string into an iso 8601 duration
dataset/ETHPy150Open fictivekin/openrecipes/scrapy_proj/openrecipes/util.py/get_isoduration