Sha256: ad5859aa23a3ae7372deb3610d65826bfc6210eb639269011103e6ac1ec09272
Contents?: true
Size: 697 Bytes
Versions: 52
Compression:
Stored size: 697 Bytes
Contents
from calendar import Calendar def meetup_day(year, month, day_of_the_week, which): candidates = [date for date in Calendar().itermonthdates(year, month) if date.month == month if date.strftime('%A') == day_of_the_week] return _choice(which)(candidates) def _choice(which): if which == 'teenth': return lambda dates: next(d for d in dates if 13 <= d.day <= 19) ix = -1 if (which == 'last') else (int(which[0]) - 1) def _func(dates): if ix < len(dates): return dates[ix] raise MeetupDayException('day does not exist') return _func class MeetupDayException(Exception): pass
Version data entries
52 entries across 52 versions & 1 rubygems