alias DayTime_Activate {
var %now $calc(60* $int($calc($ctime / 60)))
if ($1 == activate) goto $1
:setup
if (!$istok(Sun Mon Tue Wed Thu Fri Sat,$1,32)) goto syntax
var %target_day $1
var %target_hour $gettok($2,1,58))
var %target_mins $gettok($2,2-,58)
if ((%target_hour !isnum 0-23) || (. isin $2) || (%target_mins !isnum 0-59)) goto syntax
if (!$3-) goto syntax
var %day_now $asctime(%now,ddd)
var %hour_now $asctime(%now,HH)
var %mins_now $asctime(%now,nn)
var %delay_mins $calc( (%target_hour - %hour_now) *60 + (%target_mins - %mins_now) *1 )
var %target_weekday $findtok(Sun Mon Tue Wed Thu Fri Sat,%target_day,32)
var %now_weekday $findtok(Sun Mon Tue Wed Thu Fri Sat,%day_now ,32)
var %days_into_future $calc( (%target_weekday +7-%now_weekday) % 7)
if (%target_day == %day_now) { var %days_into_future $iif(%delay_mins > 0,0,7) }
var %delay_mins $calc( 24*60*%days_into_future + %delay_mins)
var %2359 $asctime($calc(%now + (24*60-1)*60),HH:nn)
var %time $iif(%delay_mins < $calc(24*60), $asctime($calc( %now + 60*%delay_mins ),HH:nn) , %2359)
echo -sc info timerDayTime_Activate_ $+ $1 $+ $2 -o %time 1 0 /DayTime_Activate $iif(%delay_mins < $calc(24*60),Activate) $1 $2 $3-
.timerDayTime_Activate_ $+ $1 $+ $2 -o %time 1 0 /DayTime_Activate $iif(%delay_mins < $calc(24*60),Activate) $1 $2 $unsafe( $3- ) $chr(124) halt $chr(124) decoded command: $3-
; the above timer moves the timer forward 1 day when the target is not within 24 hrs, otherwise executes at the target time
var %e $iif($fromeditbox,-ag,-sg)
echo %e timer targeted to activate $asctime( $calc($ctime + %delay_mins *60),ddd mmm dd yyyy HH:nn tt ) executing: $3-
echo %e To cancel this timer: /timerDayTime_Activate_ $+ $1 $+ $2 off
echo %e To see all timers created by this script: /timerDayTime_Activate_*
return
:activate
echo -a Timer set for $1 at $2-3 is now activating with command: $4-
$4-
; make next line a COMMENT to avoid activating again same time 7 days after activating
.timer 1 0 /DayTime_Activate $2 $3 $unsafe( $4- )
return
:syntax
window -ea @DayTime_Activate
echo -a $iif($1-,Invalid syntax: $1-) Syntax: /DayTime_Activate Day_of_Week Time_of_Day COMMAND [optional parameters]
echo -a If target day-of-week is same as today's day-of-week, target will be 7 days from today (Use 3-letter day)
echo -a To run alias /quiz next $asctime($ctime,dddd) at 6pm: /DayTime_Activate $asctime($ctime,ddd) 18:00 Quiz c:\data\questions.txt
}