7
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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 &]]
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Y. Kwon Mar 25 at 4:31
2
$\begingroup$
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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Y. Kwon Mar 25 at 4:26
  • $\begingroup$ @Y.Kwon you can but it is really advised against as it could detrimentally alter other functionality. $\endgroup$ – CA Trevillian Mar 25 at 20:20
  • $\begingroup$ @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. $\endgroup$ – Y. Kwon Mar 26 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.