def SingalTermday_generator_GE(tdate: date): holidays = [] US = UnitedStates() cal = US.holidays(tdate.year) for ci in cal: lstr = ci[1].split(' ')[-1] if lstr != '(Observed)': holidays.append(ci[0]) mstr = str(tdate.year) + '-' + str(tdate.month) mondays = FullMonthDays(mstr) n = 0 wn = 0 for wi in mondays: if wi.weekday() == 2: n += 1 if n == 2: break wn += 1 mondays = mondays[:wn + 1] _3rdWednesday = mondays[-1] adjmdays = [] for mi in mondays: if mi.weekday() != 5 and mi.weekday() != 6: if mi not in holidays: adjmdays.append(mi) if _3rdWednesday in adjmdays: return adjmdays[-3] else: return adjmdays[-2]
def termdays_generator(start: date, end: date): holidays = [] fyears = [yi for yi in range(start.year, end.year + 1)] US = UnitedStates() for fyi in fyears: cal = US.holidays(fyi) for ci in cal: lstr = ci[1].split(' ')[-1] if lstr != '(Observed)': holidays.append(ci[0]) termdays = [] adjstart = date(start.year, start.month, 1) adjend = date(end.year, end.month, 1) godate = adjstart while godate <= adjend: mstr = str(godate.year) + '-' + str(godate.month) mondays = monthdays(mstr) adjmdays = [] for mi in mondays: if mi.weekday() != 5 and mi.weekday() != 6: if mi not in holidays: adjmdays.append(mi) termd = adjmdays[-3] termdays.append(termd) godate = godate + relativedelta(months=1) return termdays
def SingalTermday_generator_ICE_B(tdate: date): holidays = [] US = UnitedStates() cal = US.holidays(tdate.year) for ci in cal: lstr = ci[1].split(' ')[-1] if lstr != '(Observed)': holidays.append(ci[0]) mstr = str(tdate.year) + '-' + str(tdate.month) mondays = FullMonthDays(mstr) adjmdays = [] for mi in mondays: if mi.weekday() != 5 and mi.weekday() != 6: if mi not in holidays: adjmdays.append(mi) return adjmdays[-1]