this.gettextdate = function(thestring){ //convert a string to a date, if the string is not a date, return a empty string
var i = 0, j = 0, tmpchar = "", find_tag = "";
var start_at = 0, end_at = 0, year_at = 0, month_at = 0, day_at = 0;
var tmp_at = 0, one_at = 0, two_at = 0, one_days = 0, two_days = 0;
var arydate = new array();
var tmpyear = -1, tmpmonth = -1, tmpday = -1;
var tmpdate = thestring.tolowercase();
var defdate = "";
tmpdate = tmpdate.replace(/(\d)0(\d)/g, "$1-$2");
for (i = 0; i < 9; i++){
tmpdate = tmpdate.replace(this.monthname[i].tolowercase().substr(0,3), "-00" + (i+1).tostring() + "-");
}
for (i = 9; i < 12; i++){
tmpdate = tmpdate.replace(this.monthname[i].tolowercase().substr(0,3), "-0" + (i+1).tostring() + "-");
}
tmpdate = tmpdate.replace(/jan/g, "-001-");
tmpdate = tmpdate.replace(/feb/g, "-002-");
tmpdate = tmpdate.replace(/mar/g, "-003-");
tmpdate = tmpdate.replace(/apr/g, "-004-");
tmpdate = tmpdate.replace(/may/g, "-005-");
tmpdate = tmpdate.replace(/jun/g, "-006-");
tmpdate = tmpdate.replace(/jul/g, "-007-");
tmpdate = tmpdate.replace(/aug/g, "-008-");
tmpdate = tmpdate.replace(/sep/g, "-009-");
tmpdate = tmpdate.replace(/oct/g, "-010-");
tmpdate = tmpdate.replace(/nov/g, "-011-");
tmpdate = tmpdate.replace(/dec/g, "-012-");
for (i = 0; i < tmpdate.length; i++){
tmpchar = tmpdate.charat(i);
if (((tmpchar < "0") || (tmpchar>"9")) && (tmpchar != "-")){
tmpdate = tmpdate.replace(tmpchar, "-")
}
}
while (tmpdate.indexof("–") != -1){
tmpdate = tmpdate.replace(/–/g, "-");
}
start_at = 0;
end_at = tmpdate.length-1;
while (tmpdate.charat(start_at) == "-"){
start_at++;
}
while (tmpdate.charat(end_at) == "-"){
end_at–;
}
if (start_at < end_at+1){
tmpdate = tmpdate.substring(start_at, end_at + 1);
}else{
tmpdate = "";
}
arydate = tmpdate.split("-");
if (arydate.length != 3){
return(defdate);
}
tmp_at = 0;
for (i = 0; i < 3; i++){
if (parseint(arydate[i], 10)==0){
tmp_at++;
year_at = i;
}
}
if (tmp_at > 1){
return(defdate);
}
if (tmp_at == 1){
arydate[year_at] = this.getformatyear(arydate[year_at]).tostring();
}
tmpdate = this.dateformat;
year_at = tmpdate.indexof("<yyyy>");
if (year_at == -1){
year_at = tmpdate.indexof("<yy>");
}
month_at = tmpdate.indexof("<mmmmmm>");
if (month_at == -1){
month_at = tmpdate.indexof("<mmm>");
}
if (month_at == -1){
month_at = tmpdate.indexof("<mm>");
}
if (month_at == -1){
month_at = tmpdate.indexof("<m>");
}
day_at = tmpdate.indexof("<dd>");
if (day_at == -1){
day_at = tmpdate.indexof("<d>");
}
find_tag = "000";
for (i = 0; i < 3; i++){
if (arydate[i].length == 3){
if ((arydate[i] >= "001") && (arydate[i] <= "012")){
if (find_tag != "000"){
return(defdate);
}
tmpmonth = parseint(arydate[i], 10) – 1;
switch (i){
case 0:
find_tag = "100";
one_at = parseint(arydate[1], 10);
two_at = parseint(arydate[2], 10);
break;
case 1:
find_tag = "010";
one_at = parseint(arydate[0], 10);
two_at = parseint(arydate[2], 10);
break;
case 2:
find_tag = "001";
one_at = parseint(arydate[0], 10);
two_at = parseint(arydate[1], 10);
break;
}
}
}
}
if (find_tag!="000"){
one_days = this.getmonthdays(two_at, tmpmonth);
two_days = this.getmonthdays(one_at, tmpmonth);
if ((one_at > one_days) && (two_at > two_days)){
return(defdate);
}
if ((one_at <= one_days) && (two_at > two_days)){
tmpyear = this.getformatyear(two_at);
tmpday = one_at;
}
if ((one_at > one_days) && (two_at <= two_days)){
tmpyear = this.getformatyear(one_at);
tmpday = two_at;
}
if ((one_at <= one_days) && (two_at <= two_days)){
switch (find_tag){
case "100": //default month,day,year
tmpday = one_at;
tmpyear = this.getformatyear(two_at);
if ((month_at > year_at) && (month_at > day_at)){
if (day_at > year_at){
tmpyear = this.getformatyear(one_at);
tmpday = two_at;
}
}
break;
case "010": //default day,month,year
tmpday = one_at;
tmpyear = this.getformatyear(two_at);
if (((month_at > year_at) && (month_at < day_at)) || ((month_at < year_at) && (month_at > day_at))){
if (day_at > year_at){
tmpyear = this.getformatyear(one_at);
tmpday = two_at;
}
}
break;
case "001": //default year,day,month
tmpyear = this.getformatyear(one_at);
tmpday = two_at;
if ((month_at < year_at) && (month_at < day_at)){
if (year_at > day_at){
tmpday = one_at;
tmpyear = this.getformatyear(two_at);
}
}
break;
default: //default day,year
tmpday = one_at;
tmpyear = this.getformatyear(two_at);
}
}
return(new date(tmpyear, tmpmonth, tmpday));
}
find_tag = "000";
for (i = 0; i < 3; i++){
if (parseint(arydate[i], 10) > 31){
if (find_tag!="000"){
return(defdate);
}
tmpyear = this.getformatyear(arydate[i]);
switch (i){
case 0:
find_tag = "100";
one_at = parseint(arydate[1], 10);
two_at = parseint(arydate[2], 10);
break;
case 1:
find_tag = "010";
one_at = parseint(arydate[0], 10);
two_at = parseint(arydate[2], 10);
break;
case 2:
find_tag = "001";
one_at = parseint(arydate[0], 10);
two_at = parseint(arydate[1], 10);
break;
}
}
}
if (find_tag == "000"){
if ((year_at > month_at) && (year_at > day_at)){
find_tag = "001";
}
if ((year_at > month_at) && (year_at < day_at)){
find_tag = "010";
}
if ((year_at < month_at) && (year_at > day_at)){
find_tag = "010";
}
if ((year_at < month_at) && (year_at < day_at)){
find_tag = "100";
}
switch (find_tag){
case "100":
tmpyear = parseint(arydate[0], 10);
one_at = parseint(arydate[1], 10);
two_at = parseint(arydate[2], 10);
break;
case "010":
one_at = parseint(arydate[0], 10);
tmpyear = parseint(arydate[1], 10);
two_at = parseint(arydate[2], 10);
break;
case "001":
one_at = parseint(arydate[0], 10);
two_at = parseint(arydate[1], 10);
tmpyear = parseint(arydate[2], 10);
break;
}
tmpyear = this.getformatyear(tmpyear);
}
if (find_tag == "000"){
return(defdate);
}else{
if ((one_at > 12) && (two_at > 12)){
return(defdate);
}
if ((one_at <= 12) && (two_at > 12)){
if (two_at > this.getmonthdays(tmpyear,one_at-1)){
return(new date(tmpyear, one_at-1, this.getmonthdays(tmpyear,one_at-1)));
}else{
return(new date(tmpyear, one_at-1, two_at));
}
}
if ((one_at > 12) && (two_at <= 12)){
if (one_at > this.getmonthdays(tmpyear,two_at-1)){
return(new date(tmpyear, two_at-1, this.getmonthdays(tmpyear,two_at-1)));
}else{
return(new date(tmpyear, two_at-1, one_at));
}
}
if ((one_at <= 12) && (two_at <= 12)){
tmpmonth = one_at-1;
tmpday = two_at;
if (month_at > day_at){
tmpmonth = two_at-1;
tmpday = one_at;
}
return(new date(tmpyear, tmpmonth, tmpday));
}
}
}
this.createyearlist = function(minyear, maxyear){ //create year list
var thename = this.name;
var theyearobject = document.all.item(thename + "_yearlist");
if (theyearobject == null){
return;
}
var theyear = 0;
var theyearhtml = "<select id=\"" + thename + "_yearlist\" style=\"" + this.yearliststyle + "\" tabindex=\"-1\" onchange=\"document.jsmonthview.updatemonthgrid(this)\" onblur=\"document.jsmonthview.deletemonthgrid()\">";
for (theyear = minyear; theyear <= maxyear; theyear++){
theyearhtml += "<option value=\"" + theyear.tostring() + "\">" + theyear.tostring() + "</option>";
}
theyearhtml += "</select>";
theyearobject.outerhtml = theyearhtml;
}
this.createmonthlist = function( ){ //create month list
var thename = this.name;
var themonthobject = document.all.item(thename + "_monthlist");
if (themonthobject == null){
return;
}
var themonth = 0;
var themonthhtml = "<select id=\"" + thename + "_monthlist\" style=\"" + this.monthliststyle + "\" tabindex=\"-1\" onchange=\"document.jsmonthview.updatemonthgrid(this)\" onblur=\"document.jsmonthview.deletemonthgrid()\">";
for (themonth = 0; themonth < 12; themonth++){
themonthhtml += "<option value=\"" + themonth.tostring() + "\">" + this.monthname[themonth] + "</option>";
}
themonthhtml +="</select>";
themonthobject.outerhtml = themonthhtml;
}
this.setdaylist = function(theyear, themonth, theday){ //set the month view show a date
var thename = this.name;
var thedayobject = document.all.item(thename + "_daylist");
if (thedayobject == null){
return;
}
thedayobject.value = theday.tostring();
var thefirstday = new date(theyear, themonth, 1);
var thecurrentdate = new date();
var theweek = thefirstday.getday();
if (theweek == 0){
theweek = 7;
}
var theleftday = 0;
if (themonth == 0){
theleftday = 31;
}else{
theleftday = this.getmonthdays(theyear, themonth – 1);
}
var therightday = this.getmonthdays(theyear, themonth);
var thecurrentday = theleftday – theweek + 1;
var offsetmonth = -1; //the month is previous month
var thecolor = this.invalidcolor;
var thebgcolor = this.unselectbgcolor;
var thebdcolor = thebgcolor;
var weekid = 0
var dayid = 0;
var thestyle = "";
var thedayhtml = "<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
thedayhtml += " <tr style=\"" + this.titlestyle + "\">";
for (dayid = 0; dayid < 7; dayid++){
thedayhtml += " <td width=\"10%\" style=\"" + this.weekliststyle + "\">" + this.weekname[dayid] + "</td>";
}
thedayhtml += " </tr>";
thedayhtml += " <tr>";
thedayhtml += " <td colspan=\"7\" style=\"" + this.linebgstyle + "\">";
thedayhtml += " <table style=\"" + this.linestyle + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
thedayhtml += " <tr><td></td></tr>";
thedayhtml += " </table>";
thedayhtml += " </td>";
thedayhtml += " </tr>";
for (weekid = 0; weekid < 6; weekid++){
thedayhtml += " <tr style=\"" + this.daystyle + "\">";
for (dayid = 0; dayid < 7; dayid++){
if ((thecurrentday > theleftday) && (weekid < 3)){
offsetmonth++; //the month is current month;
thecurrentday = 1;
}
if ((thecurrentday > therightday) && (weekid > 3)){
offsetmonth++; //the month is next month;
thecurrentday = 1;
}
switch (offsetmonth){
case -1:
thecolor = this.invalidcolor;
break;
case 1:
thecolor = this.invalidcolor;
break;
case 0:
if ((dayid == 0) || (dayid == 6)){
thecolor = this.weekendcolor;
}else{
thecolor = this.validcolor;
}
break;
}
if ((dayid == 0) || (dayid == 6)){
thebgcolor = this.weekendbgcolor;
}else{
thebgcolor = this.unselectbgcolor;
}
thebdcolor = this.daybdcolor;
if ((thecurrentday == theday) && (offsetmonth == 0)){
thecolor = this.selectedcolor;
thebgcolor = this.selectedbgcolor;
thebdcolor = thebgcolor;
}
if ((theyear == thecurrentdate.getfullyear()) && (themonth == thecurrentdate.getmonth()) && (thecurrentday == thecurrentdate.getdate()) && (offsetmonth == 0)){
thebdcolor = this.todaybdcolor;
}
thestyle = "border:" + this.daybdwidth + " solid " + thebdcolor + "; color:" + thecolor + "; background-color:" + thebgcolor + ";";
thedayhtml += "<td style=\"" + thestyle + "\" onmouseover=\"" + this.overdaystyle + "\" onmouseout=\"" + this.outdaystyle + "\" onmousedown=\"document.jsmonthview.createmonthgrid(" + theyear.tostring() + ", " + (themonth + offsetmonth).tostring() + ", " + thecurrentday.tostring() + ")\">";
thedayhtml += thecurrentday.tostring();
thedayhtml += "</td>";
thecurrentday++;
}
thedayhtml += "</tr>";
}
thedayhtml += " <tr style=\"" + this.footerstyle + "\" onmousedown=\"document.jsmonthview.createmonthgrid(" + thecurrentdate.getfullyear().tostring() + ", " + thecurrentdate.getmonth().tostring() + ", " + thecurrentdate.getdate().tostring() + ");\">";
thestyle = "border:" + this.daybdwidth + " solid " + this.todaybdcolor + "; " + this.todayliststyle + ";";
thedayhtml += " <td style=\"" + thestyle + "\"><br></td>";
thedayhtml += " <td colspan=\"6\" style=\"" + this.todayliststyle + "\"> " + this.todaytitle + " " + this.setdateformat(thecurrentdate.getfullyear(), thecurrentdate.getmonth(), thecurrentdate.getdate()) + "</td>";
thedayhtml += " </tr>";
thedayhtml += "</table>";
var themonthgrid = document.all.item(thename + "_monthgrid");
themonthgrid.innerhtml = thedayhtml;
}
jsMonthView1.1。对日期的判断更加精准,另外增加了自定义属性的示例代码,示例代码是将英文变成中文.(2/3)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » jsMonthView1.1。对日期的判断更加精准,另外增加了自定义属性的示例代码,示例代码是将英文变成中文.(2/3)
相关推荐
- 暂无文章
