...

View Full Version : Javascript Date Engine Ver2.1



Omega9850
05-28-2012, 02:08 PM
Well, I've updated the Javascript Date Engine (JsDE) again... Version 2.1 really has nothing new to it. I simply rewrote the code so it would be smaller.
In JsDE ver2.0 and earlier versions, I would excessively use sessionStorage("",) where normal vars would suffice. In version 2.1, I've replace nearly all of those sessionStorages to vars where it wouldn't affect it's abilities.
After this, JsDE ver2.1 is 3kb lighter than 2.0

Below is the code...

//DATE ENGINE
var deversion="2.1 Build 5.28.12"; //Date Engine Version
var deedition="Custom"; //Date Engine Edition ("Custom" or "Standard")
var fdate=new Date(); //Full Date (Fri May 11 2012 00:00:00 GMT-0700 (US Mountain Standard Time))
var mhours=fdate.getHours(); //Military Hours (0-23)
var minutes=fdate.getMinutes(); //Minutes (0-59)
var seconds=fdate.getSeconds(); //Seconds (0-59)
var gtzoffset=fdate.getTimezoneOffset(); //Timezone Displacement From UTC+0:00 In Minutes

if (gtzoffset===0)
{
localStorage.setItem("TimeZone","UTC+0:00");
}
if (gtzoffset>0)
{
if ((gtzoffset/60).toString().charAt(1)===""&&(gtzoffset/60).toString().charAt(2)==="")
{
localStorage.setItem("TimeZone","UTC-"+(gtzoffset/60)+":00");
}
if ((gtzoffset/60).toString().charAt(1)=="."&&(gtzoffset/60).toString().charAt(2)>0&&(gtzoffset/60).toString().charAt(3)==="")
{
localStorage.setItem("TimeZone","UTC-"+(gtzoffset/60).toString().charAt(0)+":"+(gtzoffset/60).toString().charAt(2)*0.6+"0");
}
if ((gtzoffset/60).toString().charAt(1)=="."&&(gtzoffset/60).toString().charAt(2)>0&&(gtzoffset/60).toString().charAt(3)>0)
{
localStorage.setItem("TimeZone","UTC-"+(gtzoffset/60).toString().charAt(0)+":"+((gtzoffset/60).toString().charAt(2)+(gtzoffset/60).toString().charAt(3))*0.6);
}
}
if (gtzoffset<0)
{
if (Math.abs(gtzoffset/60).toString().charAt(1)===""&&Math.abs(gtzoffset/60).toString().charAt(2)==="")
{
localStorage.setItem("TimeZone","UTC+"+Math.abs(gtzoffset/60)+":00");
}
if (Math.abs(gtzoffset/60).toString().charAt(1)=="."&&Math.abs(gtzoffset/60).toString().charAt(2)>0&&Math.abs(gtzoffset/60).toString().charAt(3)==="")
{
localStorage.setItem("TimeZone","UTC+"+Math.abs(gtzoffset/60).toString().charAt(0)+":"+Math.abs(gtzoffset/60).toString().charAt(2)*0.6+"0");
}
if (Math.abs(gtzoffset/60).toString().charAt(1)=="."&&Math.abs(gtzoffset/60).toString().charAt(2)>0&&Math.abs(gtzoffset/60).toString().charAt(3)>0)
{
localStorage.setItem("TimeZone","UTC+"+Math.abs(gtzoffset/60).toString().charAt(0)+":"+(Math.abs(gtzoffset/60).toString().charAt(2)+Math.abs(gtzoffset/60).toString().charAt(3))*0.6);
}
}

if (mhours===0)
{
var meridiem="AM";
var hours=mhours+12;
//Any Meridiem Dependent Variables Here
}
if (mhours>=1&&mhours<=11)
{
var meridiem="AM";
var hours=mhours;
//Any Meridiem Dependent Variables Here
}
if (mhours==12)
{
var meridiem="PM";
var hours=mhours;
//Any Meridiem Dependent Variables Here
}
if (mhours>=13 &&mhours<= 23)
{
var meridiem="PM";
var hours=mhours-12;
//Any Meridiem Dependent Variables Here
}

switch(mhours)
{
case 0:
//Any Hour Dependent Variables Here
break;
case 1:
//Any Hour Dependent Variables Here
break;
case 2:
//Any Hour Dependent Variables Here
break;
case 3:
//Any Hour Dependent Variables Here
break;
case 4:
//Any Hour Dependent Variables Here
break;
case 5:
//Any Hour Dependent Variables Here
break;
case 6:
//Any Hour Dependent Variables Here
break;
case 7:
//Any Hour Dependent Variables Here
break;
case 8:
//Any Hour Dependent Variables Here
break;
case 9:
//Any Hour Dependent Variables Here
break;
case 10:
//Any Hour Dependent Variables Here
break;
case 11:
//Any Hour Dependent Variables Here
break;
case 12:
//Any Hour Dependent Variables Here
break;
case 13:
//Any Hour Dependent Variables Here
break;
case 14:
//Any Hour Dependent Variables Here
break;
case 15:
//Any Hour Dependent Variables Here
break;
case 16:
//Any Hour Dependent Variables Here
break;
case 17:
//Any Hour Dependent Variables Here
break;
case 18:
//Any Hour Dependent Variables Here
break;
case 19:
//Any Hour Dependent Variables Here
break;
case 20:
//Any Hour Dependent Variables Here
break;
case 21:
//Any Hour Dependent Variables Here
break;
case 22:
//Any Hour Dependent Variables Here
break;
case 23:
//Any Hour Dependent Variables Here
break;
}

var d=fdate.getDate(); //Days (1-31)
var dnamedarray=new Array(7);
dnamedarray[0]="Sunday";
dnamedarray[1]="Monday";
dnamedarray[2]="Tuesday";
dnamedarray[3]="Wednesday";
dnamedarray[4]="Thursday";
dnamedarray[5]="Friday";
dnamedarray[6]="Saturday";
var dnamed=dnamedarray[fdate.getDay()]; //Days (Saturday-Sunday)

switch(dnamed)
{
case "Sunday":
var yesterday="Saturday";
var tomorrow="Monday";
//Any Day Dependent Variables Here
break;
case "Monday":
var yesterday="Sunday";
var tomorrow="Tuesday";
//Any Day Dependent Variables Here
break;
case "Tuesday":
var yesterday="Monday";
var tomorrow="Wednesday";
//Any Day Dependent Variables Here
break;
case "Wednesday":
var yesterday="Tuesday";
var tomorrow="Thursday";
//Any Day Dependent Variables Here
break;
case "Thursday":
var yesterday="Wednesday";
var tomorrow="Friday";
//Any Day Dependent Variables Here
break;
case "Friday":
var yesterday="Thursday";
var tomorrow="Saturday";
//Any Day Dependent Variables Here
break;
case "Saturday":
var yesterday="Friday";
var tomorrow="Sunday";
//Any Day Dependent Variables Here
break;
}

var m=fdate.getMonth()+1; //Months (1-12)
var mnamedarray=new Array(12);
mnamedarray[0]="January";
mnamedarray[1]="February";
mnamedarray[2]="March";
mnamedarray[3]="April";
mnamedarray[4]="May";
mnamedarray[5]="June";
mnamedarray[6]="July";
mnamedarray[7]="August";
mnamedarray[8]="September";
mnamedarray[9]="October";
mnamedarray[10]="November";
mnamedarray[11]="December";
var mnamed=mnamedarray[m-1]; //Months (January-December)

switch(mnamed)
{
case "January":
var lmonth="December";
var nmonth="February";
//Any Month Dependent Variables Here
break;
case "February":
var lmonth="January";
var nmonth="March";
//Any Month Dependent Variables Here
break;
case "March":
var lmonth="February";
var nmonth="April";
//Any Month Dependent Variables Here
break;
case "April":
var lmonth="March";
var nmonth="May";
//Any Month Dependent Variables Here
break;
case "May":
var lmonth="April";
var nmonth="June";
//Any Month Dependent Variables Here
break;
case "June":
var lmonth="May";
var nmonth="July";
//Any Month Dependent Variables Here
break;
case "July":
var lmonth="June";
var nmonth="August";
//Any Month Dependent Variables Here
break;
case "August":
var lmonth="July";
var nmonth="September";
//Any Month Dependent Variables Here
break;
case "September":
var lmonth="August";
var nmonth="October";
//Any Month Dependent Variables Here
break;
case "October":
var lmonth="September";
var nmonth="November";
//Any Month Dependent Variables Here
break;
case "November":
var lmonth="October";
var nmonth="December";
//Any Month Dependent Variables Here
break;
case "December":
var lmonth="November";
var nmonth="January";
//Any Month Dependent Variables Here
break;
}

var lyear=fdate.getFullYear()-1; //Last Year (2011)
var year=fdate.getFullYear(); //Year (2012)
var nyear=fdate.getFullYear()+1; //Next Year (2013)

if (lyear%4 === 0)
{
var lyearleapyear="Yes";
var lyearmodulusfour="Pass";
//Any Leap Year Dependent Variables Here
}
else
{
var lyearleapyear="No";
var lyearmodulusfour="Fail";
//Any Leap Year Dependent Variables Here
}
if (lyear%400 === 0)
{
var lyearleapyear="Yes";
var lyearmodulusfourhundred="Pass";
//Any Leap Year Dependent Variables Here
}
else
{
var lyearmodulusfourhundred="Fail";
if (lyearmodulusfour == "Pass")
{
var lyearleapyear="Yes";
//Any Leap Year Dependent Variables Here
}
else
{
var lyearleapyear="No";
//Any Leap Year Dependent Variables Here
}
}

if (year%4 === 0)
{
var yearleapyear="Yes";
var yearmodulusfour="Pass";
//Any Leap Year Dependent Variables Here
}
else
{
var yearleapyear="No";
var yearmodulusfour="Fail";
//Any Leap Year Dependent Variables Here
}
if (year%400 === 0)
{
var yearleapyear="Yes";
var yearmodulusfourhundred="Pass";
//Any Leap Year Dependent Variables Here
}
else
{
var yearmodulusfourhundred="Fail";
if (yearmodulusfour == "Pass")
{
var yearleapyear="Yes";
//Any Leap Year Dependent Variables Here
}
else
{
var yearleapyear="No";
//Any Leap Year Dependent Variables Here
}
}

if (nyear%4 === 0)
{
var nyearleapyear="Yes";
var nyearmodulusfour="Pass";
//Any Leap Year Dependent Variables Here
}
else
{
var nyearleapyear="No";
var nyearmodulusfour="Fail";
//Any Leap Year Dependent Variables Here
}
if (nyear%400 === 0)
{
var nyearleapyear="Yes";
var nyearmodulusfourhundred="Pass";
//Any Leap Year Dependent Variables Here
}
else
{
var nyearmodulusfourhundred="Fail";
if (nyearmodulusfour == "Pass")
{
var nyearleapyear="Yes";
//Any Leap Year Dependent Variables Here
}
else
{
var nyearleapnyear="No";
//Any Leap Year Dependent Variables Here
}
}
//DATE ENGINE END

Once again, I've attached a file containing all 3 versions of the JsDE (Custom, Standard Inflated, and Standard Deflated, I define them here (http://www.codingforums.com/showthread.php?t=261599)). You'll also notice test html files. Those simply display the output of every var for its corresponding version of the JsDE.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum