(Nearest) Weekday function

Oct 18, 2009
118
4
#1
Here's the task I'm trying to solve and something like an @weekday[date, [before|after], [format]] might be useful:

Problem:
  1. Certain reports are due on 1st and 15th of month.
  2. Certain preparations have to be done 1 business day before.
  3. The user needs a warning 2 business days before (i.e., "Need to prep tomorrow. Report due on 15th.)
  4. BUT if the 1st or 15th falls on a weekend the reports are sent the next business day. (E.g., report sent Monday 17th.)
  5. The warnings have to be on business days--a warning on Saturday the 15th won't be seen.
Assumptions:
  1. "Business" day means Monday-Friday. The function wouldn't handle holidays.
  2. Reports might have to be filed on or before the 1st and 15th rather than the next business day after.
  3. January (e.g.) and February would cause problems--you can't just pop up on the 27th, 28th, etc., "1st of Month report due." Users would get annoyed having the "2 day" warning pop up for 4 days and some would start ignoring it.

    On the other hand, if the 1st is a Monday, then having it pop up on the 27th might not have it seen for 4 days.
Function:
  1. @weekday[date, [before|after], [format]]
  2. Echo %@weekday[date] would display date if it is a weekday or -1 (or 0, etc.) if it's not.
  3. Echo %@weekday[date, "before"] (or more likely, 0 or 1) would display date if it is a weekday. If date is a weekend, it would display the nearest weekday before date.
  4. You might want to have 2 "format" parameters--one for the format of date and one for the format of the return value.
Incidentally, this is a problem I'm trying to solve, so whether such a function is added to TCC or not I would appreciate some suggestions on how to set this up. I need reports sent on or after the 1st and 15th.
 
#4
You seem to have 4 dates to handle in the course a given month:

  • the report on 1
  • the report on 15
these should be put forward 1 or 2 days if falling on a weekend

  • the prep on 13
  • the prep ad the end of the month
these should be put back 1 or 2 days if falling on a weekend.

I could envision 4 short DO loops, probably using the numeric value @DATE gives you for a given date, to test for weekdayness :-)

E.g., for the first 3 days of a month, if the day is a weekday, set a flag and leave loop.

For the last prep test, you'd need 2 tests: 1 for weekday, one for still being the same month. You'd have to start on the 26 looping to 31, using the last date that fullfills both weekdayness and correctmonthiness.