How would I add only business days to an NSDate?

前端 未结 4 1381
难免孤独
难免孤独 2021-02-04 18:55

I have an issue related to calculating business days in Objective-C.

I need to add X business days to a given NSDate.

For example, if

4条回答
  •  礼貌的吻别
    2021-02-04 19:48

    There's nothing built into NSDate or NSCalendar that counts business days for you. Business days depend to some degree on the business in question. In the US, "business day" generally means weekdays that aren't holidays, but each company determines which holidays to observe and when. For example, some businesses move observance of minor holidays to the last week of the year so that employees can be off between Christmas and New Year's Day without taking vacation.

    So, you'll need to decide exactly what you mean by business day. It should then be simple enough write a little method to calculate a future date by adding some number of business days. Then use a category to add a method like -dateByAddingBusinessDays: to NSDate.

提交回复
热议问题