Work Hours in a Month

Work Hours in a Month

Just sharing a function I made to calculate the number of work hours in a month.

It takes the input of a MONTH string (1 to 12) and does the rest based on the current year.
 
  1. MONTHS={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  2. this_MONTH=MONTHS.get((input.MONTH.toLong()  -  1));
  3. DATE_STRING="01-" + this_MONTH + "-" + (zoho.currentdate.getYear());
  4. DATE1=DATE_STRING.toDate();
  5. DATE2=DATE1.addMonth(1);
  6. DAYS=((DATE2 - DATE1)  /  86400000);
  7. HOURS_LIST={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
  8. WORK_HOURS=0;
  9. for each day in HOURS_LIST
  10. {
  11.      if((day.toLong()  <=  DAYS))
  12.     {
  13.         DATE_STRING=day + "-" + this_MONTH + "-" + (zoho.currentdate.getYear());
  14.          DATE3=DATE_STRING.toDate();
  15.         WORK_HOURS=if((((day  <=  DAYS)  &&  (DATE3.getDayOfWeek()  >  1))  &&  (DATE3.getDayOfWeek()  <  7)),(WORK_HOURS  +  8),WORK_HOURS);
  16.     }
  17. }
  18. alert WORK_HOURS;
 
If you have any questions, let me know.

John M. Whitney