Then I have this problem when the shifted time is past midnight and the alarm is broken.
Besides that script is fully functional and is being of a great help to me. To those of you who may want to use it there's a minor problem as it presents shifted date as "1h 3min 6sec" instead of "01h 03min 06sec" but that's easy for you to fix using some format(, 00).
Is there anyone out there who could please help me solving it?
Code: Select all
$sTime = formatdate (, "hh:nn:ss");
$hr = gettoken ($sTime, 1, ":");
$mn = gettoken ($sTime, 2, ":");
$sc = gettoken ($sTime, 3, ":");
$hrC = $hr * 60;
$hrMN = $hrC + $mn;
$mnC = $hrMN * 60;
$Fsec = $mnC + $sc;
$shift = input("Enter Minutes<crlf>In how much minutes the alarm should sound?", "Only integer values please." , "15");
$interv = input("Enter Interval<crlf>At which interval (in minutes) script must verify?", "Only integer values not greater than '$shift'." , "1");
end $shift < $interv, "Interval '$interv' is greater than shift '$shift'!";
$reminder = input("Enter Reminder<crlf>Any note to self?", "Enter a message in case you need a reminder." , "");
$intervS = $interv * 60;
$intervM = $intervS * 1000;
$shiftC = $shift * 60;
$shiftF = $shiftC + $Fsec;
// format duration given in seconds
$DAYS_PER_YEAR = 365.25;
$HOURS_PER_DAY = 24;
$MINS_PER_HOUR = 60;
$SECS_PER_MIN = 60;
$sep = " ";
$duration = "";
$Secs = $shiftF;
$Mins = $Secs \ $SECS_PER_MIN;
$Hours = $Mins \ $MINS_PER_HOUR;
$Days = $Hours \ $HOURS_PER_DAY;
$Years = $Days \ $DAYS_PER_YEAR;
If ($Years > 0) {
$duration = $duration . $sep . $Years . "y";
}
$Days = $Days % $DAYS_PER_YEAR;
If ($Days > 0) {
$duration = $duration . $sep . $Days . "d";
}
$Hours = $Hours % $HOURS_PER_DAY;
If ($Hours > 0) {
$duration = $duration . $sep . $Hours . "h";
}
$Mins = $Mins % $MINS_PER_HOUR;
If ($Mins > 0) {
$duration = $duration . $sep . $Mins . "min";
}
$Secs = $Secs % $SECS_PER_MIN;
If ($Secs > 0) {
$duration = $duration . $sep . $Secs . "sec";
}
// cut initial sep
$duration = substr($duration, strlen($sep));
$ctrl = 1;
// $verify = round($shiftF / $intervS); // tried $intervM, $intervS (great!)
// $verify = $shift + 1; //most reliable
$verify = ceil($shift / $interv);
// $verify = 10; //debug
WHILE ($ctrl <= $verify) {
$sTimeN = formatdate (, "hh:nn:ss");
$hrN = gettoken ($sTimeN, 1, ":");
$mnN = gettoken ($sTimeN, 2, ":");
$scN = gettoken ($sTimeN, 3, ":");
$hrCn = $hrN * 60;
$hrMNn = $hrCn + $mnN;
$mnCn = $hrMNn * 60;
$FsecN = $mnCn + $scN;
IF ($shiftF > $FsecN) {
$testctrl = $ctrl / 2;
$gt = gettoken($testctrl, "2", ".");
IF ($gt != "") { status "run: $ctrl, alarm ON - $duration ($sTime + $shift min)", "BF0000", "progress"; $ctrl++; wait($intervM); }
ELSEIF ($gt == "") { status "run: $ctrl, alarm ON - $duration ($sTime + $shift min)", "008000"; $ctrl++; wait($intervM); }
}
ELSEIF ($shiftF <= $FsecN) { $ctrl = $verify + 1; }
}
$sTimeN = formatdate (, "hh:nn:ss - yyyy/mm/dd");
// beep; beep 500, 200; beep 600, 300; //enable/disable the beep
IF ($reminder == "") { status "$duration has past!", "FF0000", alert; echo "Estimated: $duration<crlf>Now is : $sTimeN<crlf>(estimated + $interv min interval)<crlf>(year/month/day)"; }
ELSEIF ($reminder != "") { status "$duration has past! - $reminder.", "FF0000", alert; echo "Estimated: $duration<crlf>Now is : $sTimeN<crlf>(estimated + $interv min interval)<crlf>(year/month/day)<crlf 2>Reminder:<crlf>$reminder"; }
XYplorer Beta Club