Last active
August 29, 2015 14:07
-
-
Save mursts/8258557ad6230c8ca751 to your computer and use it in GitHub Desktop.
土日を除いた月末を取得する
This file contains 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 | |
#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() |
This file contains 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
workdays | |
python-dateutil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment