Created
May 25, 2018 13:48
-
-
Save albal/bc741ac5e05d105fd89d0c57cefaf888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import datetime | |
| import holidays | |
| import calendar | |
| workingdays_year = 0 | |
| uk_holidays=holidays.UK() | |
| this_year=datetime.datetime.now().year | |
| for month in range (1, 13): | |
| weekdays = [] | |
| workingdays = 0 | |
| # get current month | |
| this_month=month | |
| # get total days in months | |
| days=calendar.monthrange(this_year, this_month)[1] | |
| # create array with working days | |
| for day in range(1, days + 1): | |
| testday = datetime.date(this_year, this_month, day) | |
| if testday.weekday() < 5: | |
| weekdays.append(testday) | |
| # remove public holidays | |
| for day in weekdays: | |
| if day not in uk_holidays: | |
| workingdays = workingdays + 1 | |
| # get total working days in month | |
| print "There are",workingdays,"working days in the month of",calendar.month_name[this_month] | |
| workingdays_year = workingdays_year + workingdays | |
| print "There are a total of",workingdays_year,"in the year of",this_year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment