This code sample calculates the schedule (open, closed, or holiday) for an automated attendant, so that it can plan an appropriate announcement when someone calls in. The schedule allows for several possibilities; in fact I had to write a little document to explain it to people. This is not original code, I just cleaned it up a bit for intelligibility.

Check schedule for one AA.
Warning: don't confuse schdule.other and schdule.mode!

procedure check_one (aa: integer; schdule: schdule_type; sched_ct: char;
					 var mode: byte);

  i, day: byte;
  date:        bd_date_type;
  last_sched:  short_time_type;
  now:         short_time_type;
  time:        bd_time_type;
  use:         (use_mode, use_time, use_legend);
  bddate (date);
  get_day (day, date);
  bdtime (time);

  use := use_mode;
  { Scheduled holiday closing? }
  if schdule[day].other = 'T'      then mode := other

  { Override open? }
  else if schdule[day].other = 'O' then mode := open

  { Override closed? }
  else if schdule[day].other = 'C' then mode := closed

  { Controlled by Legend schedule? }
  else if sched_ct = '1' then use := use_legend

  { Controlled by Merlin Mail business schedule? }
  else if sched_ct = '2' then
	{ Normal closed day? }
	if schdule[day].mode = C
	  then mode := closed
	  else use := use_time;

  { Controlled by both??? }
  else if sched_ct = '3' then
	{ Special case if today is normally closed. }
	if schdule[day].mode = C then
	  { Did last mode code arrive on a previous day?  If so, ignore it,
		business schedule resets at midnight. }
	  if pxsys.legend_date < date
		then mode := closed
		else use := use_legend;
	  { Normal schedule. See what happened last, time change or mode code. }
	  for i := 1 to 4 do now[i] := time[i];
	  { Are we after closing, during open, or before open? }
	  if now >= schdule[day].end_time
		then last_sched := schdule[day].end_time
	  else if now >= schdule[day].start_time
		then last_sched := schdule[day].start_time
		else last_sched := '0000';
	  { Which was more recent, last time change or last mode code? }
	  if (pxsys.legend_date = date) and (pxsys.legend_time > last_sched)
		then use := use_legend
		else use := use_time;

  { Finally!  If use = use_mode, then mode's all set, else figure it out
	from either the last Legend mode code or the time of day. }
  if use = use_legend then
	if pxsys.legend_night then mode := closed else mode := open
  else if use = use_time then
	if time_within (schdule[day].start_time, schdule[day].end_time)
	  then mode := open
	  else mode := closed;


[Back to home page]