def strftime(dt, format):
    """
    an extended version of strftime, that introduces some new
    directives:
    %IW   iso week number
    %IY   iso year
    %IB   full month name appropriate to iso week
    %ib   abbreviated month name appropriate to iso week
    %im   month as decimal number appropriate to iso week
    """
    iso = dt.isocalendar()
    if iso[0] != dt.year:
        iso_date = dt.replace(day=1, month=1)
        format = format \
                 .replace("%IB", iso_date.strftime("%B"))\
                 .replace("%ib", iso_date.strftime("%b"))\
                 .replace("%im", iso_date.strftime("%m"))
    else:
        format = format \
                 .replace("%IB", "%B")\
                 .replace("%ib", "%b")\
                 .replace("%im", "%m")

    format = format \
             .replace("%IW", str(iso[1]))\
             .replace("%IY", str(iso[0]))\

    return dt.strftime(format)