Calendar Dates from Today Till Events

[Total: 0    Average: 0/5]

This will enable a user to keep dates for events that occur within the year or

Head Code:

<script>
var DAYS_TO_SEARCH=365;
function ask()
{
  var _msg="Please enter the number of days from now that you wish to search your schedule.";
  DAYS_TO_SEARCH = prompt(_msg,DAYS_TO_SEARCH);
}

var EVENT_CLASS=function(y,m,d,t)
{
  this.year=y;
  this.month=m;
  this._MONTH=m;if(m<10)this._MONTH="0"+m;
  this.day=d;
  this._DAY=d;if(d<10)this._DAY="0"+d;
  this.text=t;
  this.date=new Date(y,m-1,d);
  this.today=new Date();
  this.delta=Math.floor((this.date.getTime()-this.today.getTime())/86400000)+1;
  this.show=
  function(_delta)
  {
    if(this.delta<0 && !_delta)
      document.write(this.year+"/"+this._MONTH+"/"+this._DAY+" "+this.text+" was "+Math.abs(this.delta)+" days ago.<BR>");
    if(this.delta <= _delta && this.delta>0)
      document.write(this.year+"/"+this._MONTH+"/"+this._DAY+" "+this.text+" is "+this.delta+" days from now.<BR>");
  }
}
var SCHEDULE_CLASS=function()
{
  this.ITEMS=new Array();
  this.add=
  function(y,m,d,t)
  {
    var _d=new Date();var _y=_d.getYear();
    if(_y<2000)_y+=1900;
    var i=this.ITEMS.length?this.ITEMS.length:0;
    if(!y)
    {
      _y--;
      this.ITEMS[i++]=new EVENT_CLASS(_y,m,d,t);
      _y++;
      this.ITEMS[i++]=new EVENT_CLASS(_y,m,d,t);
      _y++;
      this.ITEMS[i++]=new EVENT_CLASS(_y,m,d,t);
    }
    else
      this.ITEMS[i]=new EVENT_CLASS(y,m,d,t);
  }
  this.show=
  function(_delta)
  {
    for(var i=0;i<this.ITEMS.length;i++)
    {
      this.ITEMS[i].show(_delta);
    }
  }
  this.sort=
  function()
  {
    /* bubble sort */
    for(var i=0;i<this.ITEMS.length;i++)
    {
      for(var j=i;j<this.ITEMS.length;j++)
      {
        if(this.ITEMS[i].delta>this.ITEMS[j].delta)
        {
          var x=this.ITEMS[i];
          this.ITEMS[i]=this.ITEMS[j];
          this.ITEMS[j]=x;
        }
      }
    }
  }
}
function Today()
{
  myDate=new Date();
  Y = myDate.getYear();
  M = myDate.getMonth()+1;if(M<10)M="0"+M;
  D = myDate.getDate();if(D<10)D="0"+D;
  document.write("Today is "+Y+"/"+M+"/"+D+" - Seaching window of "+DAYS_TO_SEARCH+" days.<BR>");
}
</script>

Body Code:

<script>
//ask(); /* if you do not want to use the default setting of 365 then do this */


/*
 * for items that repeat on same day every year - pass 0000 for year argument
 */
var mySchedule=new SCHEDULE_CLASS();
mySchedule.add(0000,3,30,"My Birthday");
mySchedule.add(0000,12,25,"Christmas Day");
mySchedule.add(0000,1,1,"New Year Day");
mySchedule.add(2005,1,17,"Martin Luther King's Birthday");
mySchedule.add(2005,2,21,"President's Day");
mySchedule.add(2005,5,30,"Memorial Day");
mySchedule.add(0000,7,4,"Independence Day");
mySchedule.add(2005,9,5,"Labor Day");
mySchedule.add(2005,10,10,"Columbus Day");
mySchedule.add(0000,11,11,"Veterna's Day");
mySchedule.add(2005,11,24,"Thanksgiving Day");
mySchedule.add(2006,1,16,"Martin Luther King's Birthday");
mySchedule.add(2006,2,20,"President's Day");
mySchedule.add(2006,5,29,"Memorial Day");
mySchedule.add(2006,9,4,"Labor Day");
mySchedule.add(2006,10,9,"Columbus Day");
mySchedule.add(2006,11,23,"Thanksgiving Day");
mySchedule.sort(); /* remove this if you don't want it sorted by dates */

Today();
mySchedule.show(DAYS_TO_SEARCH);
</script>

Times Viewed: 6

Leave a Reply

Your email address will not be published. Required fields are marked *