📄 date.js
字号:
else
s += "<td onclick='" + sOnClick + "' align='center' width='22' d='" + iValue + "' nav='2' onmouseover='this.runtimeStyle.color = \"#e89f2e\";' onmouseout='this.runtimeStyle.color = \"\";'><</td>";
// write out the year
s += "<td align='center' style='cursor:default;' nav='0'>" + iYear + "</td>";
// next year navigation
//
if (iYear >= _dCalMaxDate.getFullYear())
s += "<td align='center' width='22' style='cursor:default;' nav='0'> </td>";
else
s += "<td onclick='" + sOnClick + "' align='center' width='22' d='" + iValue + "' nav='2' onmouseover='this.runtimeStyle.color = \"#e89f2e\";' onmouseout='this.runtimeStyle.color = \"\";'>></td>";
s += "</tr></table></td></tr>";
// write out the months
//
var iMonth = 0;
for (i = 0; i < 4; i++)
{
s += "<tr style='height:" + (31 + (i % 2)) + "px;' onmouseover='event.srcElement.runtimeStyle.color = \"#e89f2e\";' onmouseout='event.srcElement.runtimeStyle.color = \"\";'>";
for(ii = 0; ii < 3; ii++)
{
iMonth = tmpDate.getMonth();
iValue = tmpDate.valueOf();
s += "<td onclick='" + sOnClick + "' style='font-family:Tahoma;font-size:8pt;text-align:center;border:1px solid #7288ac;cursor:hand;' d='" + iValue + "' nav='1'>" + _sCalLongMonths[iMonth] + "</td>";
tmpDate.setMonth(iMonth + 1);
}
s += "</tr>";
}
s += "</table>";
return s;
}
function ReturnDate(o)
{
var D = new Date(parseInt(o.d, 10));
if (o.nav)
{
switch (parseInt(o.nav, 10))
{
case 1:
var m = D.getMonth();
var d = D.getDate();
var a = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
if (D.getYear() % 4 == 0)
{
a[1] = 29;
}
if (o.innerHTML == "<")
{
m--;
if ((m > 0) && (d > a[m]))
{
D.setDate(a[m]);
}
D.setMonth(m);
}
else if (o.innerHTML == ">")
{
m++;
if ((m < 12) && (d > a[m]))
{
D.setDate(a[m]);
}
D.setMonth(m);
}
_oCalPopUp.document.body.innerHTML = DrawMonth(D, "parent.ReturnDate(this);", HILITE_NONE, null);
break;
case 2:
if (o.innerHTML == "<")
{
D.setYear(D.getFullYear() - 1);
}
else if (o.innerHTML == ">")
{
D.setYear(D.getFullYear() + 1);
}
_oCalPopUp.document.body.innerHTML = DrawYear(D, "parent.ReturnDate(this);");
break;
}
}
else
{
_oCalInput.value = FormatDate(D);
_oCalInput.returnValue = FormatUtcDate(D);
_oCalInput.fireEvent("onchange");
_oCalPopUp.hide();
}
}
function _parseDate(s)
{
var a = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var S = "";
var i;
for (i = 0; i < s.length; i++)
{
switch (s.charAt(i))
{
case "/": S = "/"; break;
case ".": S = "."; break;
case "-": S = "-"; break;
}
if (S.length > 0)
{
break;
}
}
var c;
var iS = 0;
for (i = 0; i < s.length; i++)
{
c = s.charAt(i);
if (c != S && !IsValidNumber(c) )
{
throw ERR_MESSAGE;
}
if (c == S)
{
iS++;
}
}
if (iS != 2)
{
throw ERR_MESSAGE ;
}
var m, d, y;
if (_iCalFormat < 4)
{
m = s.substring(0, s.indexOf(S));
d = s.substring(m.length + 1, s.indexOf(S, m.length + 1));
y = s.substr(m.length + d.length + 2);
}
else if (_iCalFormat > 3 && _iCalFormat < 8)
{
d = s.substring(0, s.indexOf(S));
m = s.substring(d.length + 1, s.indexOf(S, d.length + 1));
y = s.substr(m.length + d.length + 2);
}
else
{
y = s.substring(0, s.indexOf(S));
m = s.substring(y.length + 1, s.indexOf(S, y.length + 1));
d = s.substr(m.length + y.length + 2);
}
m = parseInt(m, 10) - 1;
if (m < 0 || m > 11)
{
throw ERR_MESSAGE ;
}
y = parseInt(PadYear(y), 10);
if (y < _dCalMinDate.getFullYear() || y > _dCalMaxDate.getFullYear())
{
throw ERR_MESSAGE ;
}
if (y % 4 == 0)
{
a[1] = 29;
}
d = parseInt(d, 10);
if (d == 0 || d > a[m])
{
throw ERR_MESSAGE ;
}
var D = new Date(y, m, d);
if ((D < _dCalMinDate) || (D > _dCalMaxDate))
{
throw ERR_MESSAGE ;
}
return D;
}
function StringToDate(s)
{
try
{
return _parseDate(s);
}
catch(e)
{
return new Date();
}
}
function ParseDate(s)
{
try
{
return _parseDate(s);
}
catch(e)
{
alert(e);
return false;
}
}
function ParseUtcDate(s)
{
if (s.length > 10)
{
// Date + Time
return new Date(parseInt(s.substr(0, 4), 10), (parseInt(s.substr(5, 2), 10) - 1), parseInt(s.substr(8, 2), 10), parseInt(s.substr(11, 2), 10), parseInt(s.substr(14, 2), 10), parseInt( s.substr( 17, 2), 10 ));
}
else
{
// date only, no time info
//
return new Date(parseInt(s.substr(0, 4), 10), (parseInt(s.substr(5, 2), 10) - 1), parseInt(s.substr(8, 2), 10));
}
}
function FormatDate(D)
{
var m = D.getMonth() + 1;
var d = D.getDate();
var y = D.getFullYear();
if (_iCalFormat % 2 == 0 )
{
y = String(y).substr(2, 2);
}
if (_iCalFormat == 2 || _iCalFormat == 3 || _iCalFormat == 6 || _iCalFormat == 7 || _iCalFormat == 10 || _iCalFormat == 11)
{
m = PadNumber(m);
d = PadNumber(d);
}
if (_iCalFormat < 4)
{
return m + _sCalSeperator + d + _sCalSeperator + y;
}
if (_iCalFormat > 3 && _iCalFormat < 8)
{
return d + _sCalSeperator + m + _sCalSeperator + y;
}
return y + _sCalSeperator + m + _sCalSeperator + d;
}
function FormatUtcDate(D)
{
return String(D.getFullYear()) + "-" + PadNumber( String(D.getMonth() + 1)) + "-" + PadNumber(String(D.getDate())) + "T" + PadNumber(String(D.getHours())) + ":" + PadNumber(String(D.getMinutes())) + ":00";
}
function PadNumber(s)
{
if (String(s).length == 1)
{
return "0" + s;
}
return s;
}
function PadYear(s)
{
s = new String(s);
if (s.length == 4)
{
return s;
}
if (s.length == 1)
{
s = 0 + s;
}
if (parseInt(s, 10) < 30)
{
return "20" + s;
}
return "19" + s;
}
function FormatUtcDateTime(s)
{
var f = 0;
var hh = parseInt(s.substr(11, 2), 10);
var mm = s.substr(14, 2);
var ss = s.substr(17, 2);
var tt = "";
switch (f)
{
case 0: case 1: case 4: case 5:
if (hh == 12)
{
tt = " PM";
}
else if (hh > 12)
{
hh = hh - 12;
tt = " PM";
}
else
{
tt = " AM";
}
break;
}
switch (f)
{
case 1: case 3: case 5: case 7:
hh = PadNumber(hh);
break;
}
if (f > 3)
{
return FormatDate(ParseUtcDate(s)) + " " + hh + ":" + mm + ":" + ss + tt;
}
else
{
return FormatDate(ParseUtcDate(s)) + " " + hh + ":" + mm + tt;
}
}
// Returns the first day of the week that contains the given date
function GetFirstDayOfWeek( D )
{
var firstDay = new Date( D.getTime( ) - ( D.getDay( ) * 24 * 60 * 60 * 1000 ) );
return new Date( firstDay.getTime( ) + ( _iCalStartDay * 24 * 60 * 60 * 1000 ) );
}
// Returns the last day of the week that contains the given date
function GetLastDayOfWeek( D )
{
var firstDay = GetFirstDayOfWeek( D );
return new Date( firstDay.getTime( ) + ( 6 * 24 * 60 * 60 * 1000 ) ); // Add 6 days to the first day of the week
}
function IsValidNumber(n)
{
if (n == null)
return false;
var l = n.length;
if (l == 0)
return false;
var s = 0;
if (n.charAt(0) == "-")
s = 1;
var i,c;
for (i = s; i < l; i++)
{
c = n.charCodeAt(i);
if (c < 46 || c > 57)
return false;
}
return true;
}
function Trim(s)
{
return s.replace(/^\s+|\s+$/g,'');
}
InitCalendar( ORG_DATE_FORMAT, ORG_DATE_SEPARATOR, ORG_DATE_START_DAY );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -