(Nearest) Weekday function

Oct 18, 2009
362
17
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.
 
May 20, 2008
473
2
It's not exactly what you are looking for, but I just added some week, month, quarter aliases here. You might be able to get some ideas from them.
 
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.
 
Oct 18, 2009
362
17
I haven't worked this out in detail, but it looks like this is the approach, using Charles Dye's @INLIEU function:

Set DueDate=8/15/2017 (Saturday)

Set DueDate=@INLIEU[DueDate, after] (returns Monday 8/17/2017)
Set PrepDate=@INLIEU[DueDate - 1, before] (returns Friday 8/14)
Set WarnDate=@INLIEU[PrepDate -1, before] (returns Thursday 8/13)
 
Similar threads
Thread starter Title Forum Replies Date
C proper function.... Suggestions 6
Joe Caverly Done Function that returns environment variable type Suggestions 1
Charles Dye @IPADDRESSV6 function Suggestions 1
R @BTWN[low number, high number] function Suggestions 0
mfarah Done pdir /(k) for the output of the @CKSUM function. Suggestions 0
E Done Support for IPv6 (ping function) Suggestions 5
Joe Caverly Done ISLIBRARY Conditional Expression Status Test and Function Suggestions 0
A @REALPATH variable function. Suggestions 0
rps Declined @ffind[] function. Suggestions 3
K_Meinhard Done @dowi function Suggestions 2
N Done Add display options to new HASH function Suggestions 1
mfarah Done Posix 100.32 compliant %@cksum[] function. Suggestions 12
Joe Caverly Function that converts an expression into a date value Suggestions 0
mikea Done Function to create GUID Suggestions 13
S Declined Character / string classification function Suggestions 9
S Done Enhanced ALIAS, SET, ESET and FUNCTION commands Suggestions 0
M Done Enhancement to @PID function... Suggestions 4
M Declined Function to to verify file name validity... Suggestions 4
S Done Enhanced FUNCTION and ALIAS definition syntax Suggestions 0
S Done Window positioning commands and current position function Suggestions 0
S Declined Indirect function specification Suggestions 2
S Done Command and help enhancement, esp. ALIAS, FUNCTION and SET Suggestions 2
Charles Dye Done @PLUGINVER function Suggestions 0
Charles Dye Done v11 idea - Date picker function Suggestions 3

Similar threads