8

I'm building my own HolidayCalendar.

I want some Saturdays to be business days.

But Mathematica considers every Saturday a holiday, even for my HolidayCalendar.

For instance,

DayRange[DateObject[{2020,1,1}], DateObject[{2020,1,31}], "BusinessDay", 
  HolidayCalendar -> { "Gregorian" -> {{True&, #==1&, #==1&}}}]

gives me no Saturdays and no Sundays, of course.

Is it possible to change this behavior?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Y. Kwon
  • 565
  • 2
  • 8

2 Answers2

1

There doesn't seem to be a straightforward way to just use DayRange[], so one has to use Select[] + Complement[] with DayRange[]:

With[{d0 = DateObject[{2020, 1, 1}], d1 = DateObject[{2020, 1, 31}]}, 
     Select[Complement[DayRange[d0, d1], 
                       DayRange[d0, d1, "Holiday",
                                HolidayCalendar ->
                                {"Gregorian" -> {{True &, # == 1 &, # == 1 &}}}]],
            DayName[#] =!= Sunday &]]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • Thank you. Unfortunately, my question is how to change the default behavior of holidaycalendar. Actually, I want to use my own HolidayCalendar in many time series-related functions. Not just to get the list of business days. – Y. Kwon Mar 25 '20 at 04:31
1
Clear["Global`*"]

Assuming that you want six business day (Mon - Sat) per week

businessDays[start_DateObject, end_DateObject] :=
 Sort[
  Complement[
   Flatten[
    DayRange[start, end, #] & /@
     {Monday, Tuesday, Wednesday, Thursday, 
      Friday, Saturday}],
   DayRange[start, end, "Holiday", 
    HolidayCalendar -> {"UnitedStates", "Default"}]]]

businessDays[
 DateObject[{2020, 1, 1}],
 DateObject[{2020, 1, 31}]]

enter image description here

Note that Mon 20 Jan 2020 is also a US holiday.

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • Thank you for your answer. But the reason I'm building my own HolidayCalendar is that I want to use it in many other builtin functions. Maybe I can make a wrapper function for every builtin functions I need. I'm just wondering if I can change the default behavior or not. – Y. Kwon Mar 25 '20 at 04:26
  • @Y.Kwon you can but it is really advised against as it could detrimentally alter other functionality. – CA Trevillian Mar 25 '20 at 20:20
  • @CATrevillian Do you mean that I can make Saturdays business days? In some countries or in some industries, they work on Saturday. I think it should be more flexible about the definition of holidays. – Y. Kwon Mar 26 '20 at 00:50