2
$\begingroup$

Not clear from DayMatchQ doc page but doesn't seem to work for say alternatives the way MatchQ does, eg

DayRange[Today,DayPlus[Today,30]] // Select[DayMatchQ[#,Monday | Wednesday | Friday]]

Returns {} as opposed to say matching Monday only. Is there a different syntax or workaround?

Don't tell me need to OR a list of DayMatchQ, ie WL diminishing orthogonality

$\endgroup$
1
  • $\begingroup$ DayMatchQ strictly takes only the following day types: All (default), "Weekday", "Weekend", Monday through Sunday, "EndOfMonth", "BeginningOfMonth", "BusinessDay", and "Holiday". No alterrnatives allowed. $\endgroup$ Aug 10 at 19:48

2 Answers 2

3
$\begingroup$

I assume that DayMatchQ is more complicated than just matching a form. One workaround would be to use DayName:

Select[
  DayRange[Today, DayPlus[Today, 30]], 
  MemberQ[{Monday, Wednesday, Friday}, DayName[#]] &]
$\endgroup$
2
$\begingroup$

If we assume our data is store in data variable:

data = DayRange[Today, DayPlus[Today, 30]];
  1. We have DateSelect for date operations:
DateSelect[data, MatchQ[#DayName, Monday | Wednesday | Friday] &] 
  1. If you combine the Listable feature (not mentioned in Attributes) of DayName and Pick, you can get a faster alternative (almost 3 times faster + using 4 times less memory):
Pick[data, DayName@data, Monday | Wednesday | Friday]
  1. If you really care about performance, you can use numeric calculation instead which is around 30 times faster than the previous version while consuming 1/3 of its memory:
Pick[data, Mod[IntegerPart[(AbsoluteTime /@ data)/86400.], 7], 0 | 2 | 4]

Of course all the outputs are the same. The timing was measured with RepeatedTiming on your sample data.

$\endgroup$

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.