Skip to content

Instantly share code, notes, and snippets.

@mursts
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mursts/8258557ad6230c8ca751 to your computer and use it in GitHub Desktop.
Save mursts/8258557ad6230c8ca751 to your computer and use it in GitHub Desktop.
土日を除いた月末を取得する
#!/usr/bin/env python
#coding: utf-8
import datetime
import workdays
from dateutil import relativedelta
def is_last_working_day_of_month(target_date):
first_day_of_next_month = target_date + relativedelta.relativedelta(months=1)
end_of_this_month = datetime.date(first_day_of_next_month.year,
first_day_of_next_month.month,
1)
return workdays.workday(end_of_this_month, -1, []) == target_date
def main():
today = datetime.date.today()
if is_last_working_day_of_month(today):
print 'last working day'
else:
print 'not last working day'
if __name__ == '__main__':
main()
workdays
python-dateutil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment