/*Tong_Zuu*/ var CscCalendar = function(){ var dayOfTimeStemp = 86400000; var hourOfTimeStemp = dayOfTimeStemp/24; var minuteOfTimeStamp = hourOfTimeStemp/60; var secondOfTimeStamp = minuteOfTimeStamp/60; this.formatDate = "-"; this.nDayOfMonth = new Array(0,31,0,31,30,31,30,31,31,30,31,30,31); this.__dd = "0"; this.__tmpDD =0; this.__mm = "0"; this.__tmpMM = 0; this.__yyyy = "0000"; this.__tmpYYYY = 0; this.__hh = 0; this.__tmpHH = 0; this.__min = 0; this.__tmpMin = 0; this.__ss = 0; this.__tmpSS = 0; var nDayOfMon = 28; var nDayOfYear = 365; this.setCscCalendar = function(strCalendar){ if(strCalendar.indexOf("-") > -1 && strCalendar.length == 10){ var tmp = strCalendar.split("-"); if(tmp[0].length == 2){ this.nDayOfMonth[2] = 32 - new Date(tmp[2], 1, 32).getDate(); nDayOfYear = (parseInt(this.nDayOfMonth[2],10)==29)?366:365; this.setDD(tmp[0]); this.setMM(tmp[1]); this.setYYYY(tmp[2]); }else if(tmp[0].length == 4){ this.nDayOfMonth[2] = 32 - new Date(tmp[0], 1, 32).getDate(); nDayOfYear = (parseInt(this.nDayOfMonth[2],10)==29)?366:365; this.setDD(tmp[2]); this.setMM(tmp[1]); this.setYYYY(tmp[0]); }else{ this.nDayOfMonth[2] = 32 - new Date(1900, 1, 32).getDate(); nDayOfYear = (parseInt(this.nDayOfMonth[2],10)==29)?366:365; this.setDD(01); this.setMM(01); this.setYYYY(1900); } }else if(strCalendar == "now"){ var ndate = new Date(); this.nDayOfMonth[2] = 32 - new Date(ndate.getYear(), 1, 32).getDate(); nDayOfYear = (parseInt(this.nDayOfMonth[2],10)==29)?366:365; this.setDD(ndate.getDate()); this.setMM(ndate.getMonth()+1); this.setYYYY(ndate.getYear()); }else{ this.nDayOfMonth[2] = 32 - new Date(1900, 1, 32).getDate(); nDayOfYear = (parseInt(this.nDayOfMonth[2],10)==29)?366:365; this.setDD(01); this.setMM(01); this.setYYYY(1900); } } this.getValueInt = function(){ return this.__yyyy+this.__mm+this.__dd; } this.beforeDate = function(timeStemp){ if(this.getNumDate(this.getTimeStamp()) < this.getNumDate(timeStemp))return true; return false; } this.beforeEqualDate = function(timeStemp){ if(this.getNumDate(this.getTimeStamp()) <= this.getNumDate(timeStemp))return true; return false; } this.beforeEqualDateTime = function(timeStemp){ if(this.getTimeStamp() <= timeStemp)return true; return false; } this.afterEqualDateTime = function(timeStemp){ if(this.getTimeStamp() >= timeStemp)return true; return false; } this.afterEqualDate = function(timeStemp){ if(this.getNumDate(this.getTimeStamp()) >= this.getNumDate(timeStemp))return true; return false; } this.afterDate = function(timeStemp){ if(this.getNumDate(this.getTimeStamp()) > this.getNumDate(timeStemp))return true; return false; } this.getNumDate = function(timeStemp){ var num = 0; if(timeStemp > dayOfTimeStemp){ num = timeStemp/dayOfTimeStemp; } return num; } this.incDate = function(){ this.incDD(); } this.getDDMMYYYY = function(){ return this.getDD()+this.formatDate+this.getMM()+this.formatDate+this.getYYYY(); } this.getYYYYMMDD = function(){ return this.getYYYY()+this.formatDate+this.getMM()+this.formatDate+this.getDD(); } this.getTimeStamp = function(){ //alert(parseInt(this.__tmpYYYY)+" | "+parseInt(this.__tmpMM)+" | "+parseInt(this.__tmpDD)+" | "+parseInt(this.__tmpHH)+" | "+parseInt(this.__tmpMin)+" | "+parseInt(this.__tmpSS)); return parseInt(this.__tmpYYYY,10)+parseInt(this.__tmpMM,10)+parseInt(this.__tmpDD,10)+parseInt(this.__tmpHH,10)+parseInt(this.__tmpMin,10)+parseInt(this.__tmpSS,10); } this.setFormatDate = function(format){ this.formateDate = format; } /* Medthod Set And Get Default*/ this.getDD = function(){ if(parseInt(this.__dd,10) < 10){ return "0"+parseInt(this.__dd,10); } return this.__dd; } this.getMM = function(){ if(parseInt(this.__mm,10) < 10)return "0"+parseInt(this.__mm,10); return this.__mm; } this.getYYYY = function(){ return this.__yyyy; } this.getHH = function(){ if(parseInt(this.__hh,10) < 10)return "0"+parseInt(this.__hh,10); return this.__hh; } this.getMin = function(){ if(parseInt(this.__min,10) < 10)return "0"+parseInt(this.__min,10) return this.__min; } this.getSS = function(){ if(parseInt(this.__ss,10) < 10)return "0"+parseInt(this.__ss,10); return this.__ss; } this.setDD = function(dd){ //alert("before "+dd); if(parseInt(this.getDD(),10) != parseInt(dd,10)){ this.__tmpDD = parseInt(dd,10)*parseInt(dayOfTimeStemp,10); } this.__dd = dd; //alert("after "+dd+); //alert("after this "+this.__dd); } this.setMM = function(mm){ if(parseInt(this.getMM(),10) != parseInt(mm,10)){ this.__tmpMM = (parseInt(this.getNumDayOfYearToNow(mm),10))*parseInt(dayOfTimeStemp,10); } this.__mm = mm; } this.setYYYY = function(yyyy){ if(parseInt(this.getYYYY(),10) != parseInt(yyyy,10)){ this.__tmpYYYY = (parseInt(yyyy,10)*nDayOfYear)*parseInt(dayOfTimeStemp,10); } this.__yyyy = yyyy; } this.setHH = function(hh){ this.__hh = hh; } this.setMin = function(mins){ this.__min = mins; } this.setSS = function(ss){ this.__ss = ss; } //End Set and Get Default this.incDD = function(){ this.setDD(parseInt(this.getDD(),10)+1); var cd = 32 - new Date(this.getYYYY(), parseInt(this.getMM(),10)-1, 32).getDate(); if(parseInt(this.getDD(),10)>cd){ this.incMM(); this.setDD(parseInt(this.getDD(),10)-cd); } } this.incMM = function(){ this.setMM(parseInt(this.getMM(),10)+1); if(parseInt(this.getMM(),10)>12){ this.incYYYY(); this.setMM(parseInt(this.__mm,10)-12); } } this.incYYYY = function(){ this.setYYYY(parseInt(this.getYYYY(),10)); } this.getNumDayOfYearToNow = function(mm){ var numDay = 0; var i = 1; while(i < parseInt(mm,10)){ numDay+=parseInt(this.nDayOfMonth[i++],10); //alert(this.nDayOfMonth+" -- "+parseInt(this.nDayOfMonth[i++],10)); } return numDay; } this.decDD = function(){ this.setDD(parseInt(this.getDD(),10)-1); if(parseInt(this.getDD(),10) == 0){ this.decMM(); var cd = 32 - new Date(this.getYYYY(), parseInt(this.getMM(),10)-1, 32).getDate(); this.setDD(parseInt(cd,10)); } } this.decMM = function(){ this.setMM(parseInt(this.getMM(),10)-1); if(parseInt(this.getMM(),10) == 0){ this.setMM(12); this.decYYYY(); } } this.decNumDD = function(num){ for(i=0;i<parseInt(num,10);i++){ this.decDD(); } } this.decYYYY = function(){ this.setYYYY(parseInt(this.getYYYY(),10)-1); } this.getMessageError = function(){ return "xxxxxxxx"; } }