def meetup(year, month, week, day_of_week): WEEK_GETTER = { "1st": lambda x: x[0], "2nd": lambda x: x[1], "3rd": lambda x: x[2], "4th": lambda x: x[3], "5th": lambda x: x[4] if len(x) == 5 else raise_(), "last": lambda x: x[-1], "teenth": lambda x: list(filter(lambda y: 13 <= y[2] < 20, x))[0], } cal = Calendar() month_cal = list( filter( lambda x: x[0] == year and x[1] == month and x[3] == WEEKDAY_NAMES[ day_of_week], cal.itermonthdays4(year, month), )) return date(*WEEK_GETTER[week](month_cal)[:-1])
# testing import sys sys.path.append('.') from libreoffice_py import document from calendar import Calendar from datetime import date today = date.today() calc = document.Calc() sheet = calc.get_sheets()[0] month = 4 cal = Calendar(firstweekday=0) monthdates = [ f'{d[0]}.{d[1]}.{d[2]}' for d in cal.itermonthdays4(today.year, month) if d[3] not in (5, 6) and d[1] == month ] data = [['Firm', 'BRIGHT', '', '', ''], ['Address', 'Street no.', '', '', ''], ['Employee', 'Jack Sprot', '', '', ''], [ 'Date', 'Arrive at', 'Sign at arrival', 'Leave at', 'Sign at arrival' ]] for d in monthdates: data.append([d, '', '08:00', '', '18:00']) for line in data: print(line)
print(calendar.monthrange(2021,10)) print(calendar.monthcalendar(2019, 10)) print(calendar.prmonth(2021, 10)) print(calendar.prcal(2021)) print(calendar.day_name[0]) print(calendar.day_abbr[0]) print(calendar.month_name[1]) print(calendar.month_abbr[1]) print('--------------------------------') c = Calendar() print(list(c.itermonthdates(2021, 7))) print(list(c.itermonthdays2(2020, 7))) print(list(c.itermonthdays3(2021, 7))) print(list(c.itermonthdays4(2021, 7))) print('--------------------------------') tx = TextCalendar() print(tx.formatmonth(2021, 9)) print(tx.prmonth(2021, 9)) print(tx.formatyear(2021)) print(tx.pryear(2021)) print('---------------------------------') hc = HTMLCalendar() print(hc.formatmonth(2021, 10)) print(hc.formatyear(2021)) print(hc.formatyearpage(2021))