Skip to content

Instantly share code, notes, and snippets.

@carlosdelfino
Last active October 31, 2022 15:20
Show Gist options
  • Save carlosdelfino/b3505ff43eb037c0cb824b2859d6ad7b to your computer and use it in GitHub Desktop.
Save carlosdelfino/b3505ff43eb037c0cb824b2859d6ad7b to your computer and use it in GitHub Desktop.
Obtém o primeiro e último dia útil de cada mês.
resmin = []
for month in range(1, 13):
calmin = calendar.monthcalendar(year, month)
for i, w in enumerate(calmin):
for j, d in enumerate(w):
if 0 == d:
calmin[i][j] = 32
day = min([week[0:5] for week in calmin][0])
if day == 32:
day = min([week[0:5] for week in calmin][1])
resmin.append(
"{:02d}/{:02d}/{:4d}".format(day, month, year))
import calendar
year = 1997
resmax = []
for month in range(1, 13):
resmax.append(
"{:02d}/{:02d}/{:4d}".format(
max(max(week[0:5] for week in calendar.monthcalendar(year, month))), month, year))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment