Attached is a slightly modified alarm.xml.  It handles single hour values
for timestamps.  The alarm search also seemed to have an undocumented
feature to allow an alarm to be set in x minutes-from-now.   This is
redundant with the timer function.  The timer function could therefore
probably be removed, and maybe timer could be aliased to alarm for backward
compatibility in the next release.  I updated the help text to indicate the
minutes-from-now feature.


Monty


-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
<search function="alarm">
  <name>Alarm</name>
  <description>
    Schedule an alarm to go off at a certain time. The alarm message is optional. All times are in Military (24hr) Time. 
    <br/>A minutes-from-now value can also be specified instead of a timestamp.
    <br/>Alarm only supports only a single alarm.<br/>
    <div class="helpboxDescLabels">Usage:</div>
  	<table class="helpboxDescTable">
  		<tr><td>Set Alarm</td><td> - </td><td>alarm &lt;<i>time or delay</i>&gt; [&lt;<i>message</i>&gt;]</td></tr>
  		<tr><td>Cancel Alarm</td><td> - </td><td>alarm cancel</td></tr>
  	</table>
    <div class="helpboxDescLabels">Example:</div>
    <table class="helpboxDescTable">
  		<tr><td>alarm 14:00 Staff Meeting</td></tr>
	      <tr><td>alarm 5 Staff Meeting in 5 minutes</td></tr>
  	</table>
  </description>
  <category>Functions</category>
  <contributor>Monty Scroggins</contributor>
  <contributor>Ben Williams ([EMAIL PROTECTED])</contributor>
  
  <script><![CDATA[
    var alarmTime;
    var curTime;
    var alarmMsg;
    var alNum;
    var parsedLine;
    var parsedMsg;
     
    function alarm(t) 
    {
      if( nullArgs("alarm",t) )
        return false;
        
      if( t.match(/^cancel.*$/i) ) 
      {
        clearInterval(alNum);
        setSearchWindowText("Alarm Canceled.");
        setTimeout("document.deff.q.value='';",1000);
      }
      else if( parsedLine = t.match(/(\d?\d\:\d\d)\s*(.*)/) ) 
      {
		if( parsedLine[1] != null && parsedLine[1].length != 0) { 
		  if(parsedTime = parsedLine[1].match(/(\d?\d):(\d\d)/)) {
			alarmTimeHours = parsedTime[1];
                  if (alarmTimeHours.length == 1) 
                  {
                  alarmTimeHours='0'+alarmTimeHours;
                  }
			alarmTimeMins = parsedTime[2];

			if(alarmTimeHours > 23) alarmTimeHours = 23;
			if(alarmTimeMins > 59) alarmTimeMins = 59;
			alarmTime = alarmTimeHours+":"+alarmTimeMins;
		  }
		}
          
        parsedMsg = parsedLine[2];
        alarmMsg =  'Alarm: ' + alarmTime + '\n\nAlarm has Expired';
          
        if(parsedMsg != null && parsedMsg.length != 0 )
          alarmMsg = 'Alarm: ' + alarmTime + '\n\n' + parsedMsg;
          
        alarmOn();
		setSearchWindowText("Alarm Set for "+alarmTime);
		setTimeout("document.deff.q.value='';",1000);
      }
	  else if( parsedLine = t.match(/^(\d+)\s*(.*)$/) )
	  {
        if( parsedLine[1] != null && parsedLine[1].length != 0) {
		  var dt = new Date();
		  minutesToAdd = parsedLine[1];
		  alarmTimeMs = Date.parse(dt.toString()) + (minutesToAdd * 60000);
		  alarmTimeDate = dt.setTime(alarmTimeMs);
		  alarmTime = IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes());
		}
		
        parsedMsg = parsedLine[2];
        alarmMsg =  'Alarm: ' + alarmTime + '\n\nAlarm has Expired';
          
        if(parsedMsg != null && parsedMsg.length != 0 )
          alarmMsg = 'Alarm: ' + alarmTime + '\n\n' + parsedMsg;
          
        alarmOn();
		setSearchWindowText("Alarm Set for "+alarmTime);
        setTimeout("document.deff.q.value='';",1000);
	  }
      else 
	  {
		window.alert("Sorry, the timestamp you entered for the alarm could not be read.\n\nThe format should be HH:MM in 24-hour time, or the number of minutes from now for the alarm to go off.");
        return;
      }
    }

    function IfZero( num ) 
    {
      return (num <= 9) ? ("0" + num) : num;
    }

    function alarmOn() 
    {
      var dt = new Date();
      curTime = IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes());
      if( alarmTime == curTime )
      {
        clearInterval(alNum);
        window.alert(alarmMsg);
      }
      else
        alNum=setTimeout("alarmOn()", 6000)
    }
  ]]></script>

  <copyright>
	Copyright (c) 2002 David Bau
	Distributed under the terms of the
	GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>

Reply via email to