Gmail Script: Time of Day based filter
<p>Hoping someone could help me on this!</p>

<p>I have a scout alarm system with access sensors. Everytime a specific door is opened I would receive an email of that activity. Being that there are no time of day notifications from Scout, it's either on or off, I wanted to handle this at the email end using Google Apps Script for Gmail.</p>

<p>Monday through Friday - Any emails coming from the alert system before 8am and after 6PM should go to my Inbox, otherwise it should go to the trash.</p>

<p>Saturday through Sunday - All emails coming from the alert system should come to my inbox.</p>

<p>Please tell me this is possible!!!</p>

<p>-UPDATE-
Here is a beta code for this but it doesn't seem to be working. I get a flood of ALL messages in my Inbox at weird times, hopefully someone can help clean it up?</p>

<pre><code>            function MoveMsgBasedOnTime() 
{
   //Enter the Label you created in your Google Apps Account for scout@#######.com
          var Label = GmailApp.getUserLabelByName("2 - Scout");

           //Retrieve All Messages with Matching Label 
         var Threads = Label.getThreads();
        for (var i = 0; i &lt; Threads.length; i++) 
   {
    var Msgs = Threads[i].getMessages();

     for (var j=0;j &lt; Msgs.length ;j++)
     {
     var MsgTime = new Date();
      MsgTime = Msgs[j].getDate();
       MsgTime.getDay();



       //Test For Day of Week

       //If Sunday (0) or Saturday (5)
       if (MsgTime.getDay() == 0 || MsgTime.getDay() == 6)
       {
         var test ="Weekend";
         //Move To Inbox
         Threads[i].moveToInbox();

       }

        //If Monday(1), Tuesday (2), Wednesday (3), Thursday (4), Friday (5)
        if (MsgTime.getDay() == 1 || MsgTime.getDay() == 2 || MsgTime.getDay() == 3 || MsgTime.getDay() == 4 || MsgTime.getDay() == 5 )
       {
         var test ="Weekday";


         // Time Interval To Delete Message
         var startTime = '8:00 AM';
         var endTime   = '7:30 PM';

         var now       = new Date();
         var startDate = dateObj(startTime);
         var endDate   = dateObj(endTime);
         var Label = GmailApp.getUserLabelByName("2 - Scout");

         var actionToTake = now &lt; endDate &amp;&amp; now &gt; startDate ? 'delete' : 'move';

            //If Message Time is Between 8am and 6pm Take Action to Move to Trash
         if (actionToTake == "delete")
           ;

         //If Message Time is Before 8am or After 6pm Take Action to Move to Inbox
         if (actionToTake == "move")
           Threads[i].removeLabel(Label);
             Threads[i].moveToInbox();
       }
     }
    }
   }

                //Function To Parse Time from Date for Comparisson using startTime &amp; endTime variables above
                function dateObj(d) 
             {
                       var parts = d.split(/:|\s/),
                      date  = new Date();
                   if (parts.pop().toLowerCase() == 'pm') parts[0] = (+parts[0]) + 12;
                  date.setHours(+parts.shift());
                  date.setMinutes(+parts.shift());
                 return date;
                   }
</code></pre>