fwarren

Compute Workdays in Pyton

Mar 8th, 2017
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. import workdays  # pip install workdays
  2. import datetime
  3.  
  4. # holidays from https://www.timeanddate.com/holidays/us/2021
  5. holidays = [(lambda x:  datetime.datetime.strptime(x ,"%Y-%m-%d").date()  ) (x) for x in [
  6.     "2017-01-01","2017-05-29","2017-07-04","2017-09-04","2017-11-24","2017-11-25","2017-12-25",
  7.     "2018-01-01","2018-05-28","2018-07-04","2018-09-03","2018-11-22","2018-11-23","2018-12-25",
  8.     "2019-01-01","2019-05-27","2019-07-04","2019-09-02","2019-11-28","2019-11-29","2019-12-25"
  9.     "2020-01-01","2020-05-25","2020-07-03","2020-09-07","2020-11-26","2020-11-27","2020-12-25"
  10.     "2020-12-31","2021-05-31","2021-07-05","2021-09-06","2021-11-25","2021-11-26","2021-12-25"
  11.     "2021-12-31","2022-05-30","2022-07-04","2022-09-05","2022-11-24","2022-11-25","2022-12-24"
  12.     "2023-01-02","2023-05-29","2023-07-04","2023-09-04","2023-11-22","2023-11-23","2023-12-26"
  13.     "2024-01-01","2024-05-27","2024-07-04","2024-09-02","2024-11-28","2024-11-29","2024-12-25"
  14.     "2025-01-01","2025-05-26","2025-07-04","2025-09-01","2025-11-27","2025-11-28","2025-12-25"
  15. ]]
  16.  
  17.  
  18.  
  19. max(workdays.networkdays(datetime.datetime.strptime(boat["fabEnd"],"%Y-%m-%d").date(),
  20. datetime.datetime.strptime(boat["paintStart"],"%Y-%m-%d").date(), holidays) -2, 0)
  21.  
  22. start = datetime.datetime.strptime('03-15-2017','%m-%d-%Y').date()
  23. end = datetime.datetime.strptime('03-27-2017','%m-%d-%Y').date()
  24.  
  25. print "Number of workdays %g" % workdays.networkdays(start, end, holidays)
Advertisement
Add Comment
Please, Sign In to add comment