All pastes #104399 Raw Edit

Untitled

public python v1 · immutable
#104399 ·published 2006-07-28 21:22 UTC
rendered paste body
import datetimeimport calendardef day_in_1970_from_month_and_week(month, week):    if month < 1 or month > 12 or week < 1 or week > 5:        raise ValueError("invalid time: month=%d, week=%d" % (month, week))    oneday = datetime.timedelta(days=1)    oneweek = datetime.timedelta(days=7)    first_sunday = datetime.date(1970, month, 1)    while first_sunday.weekday() != calendar.SUNDAY:        first_sunday += oneday    while True:        day = first_sunday + (oneweek * (week - 1))        if day.month != month:            week -= 1        else:            break    return day.daydef format_tz_time_string(month, week, hour):    day = day_in_1970_from_month_and_week(month, week)    return "1970%02i%02iT%02i0000" % (month, day, hour)