📄 sunraiseset.html
字号:
if (oneChar == "." && !oneDecimal)
{
oneDecimal = true;
continue;
}
if (oneChar < "0" || oneChar > "9")
{
return false;
}
}
return true;
}
//*********************************************************************/
// isValidInput makes sure valid input is entered before going ahead to
// calculate the sunrise and sunset. False is returned if an invalid entry
// was made, true is the entry is valid.
// 计算日出和日落之前确保输入是有效的。所有项都有效返回true;否则返回false。
function isValidInput(f, index, latLongForm)
{
if (f["day"].value == "")
{ // see if the day field is empty
alert("请先输入日期再计算.");
return false;
}
else if (f["year"].value == "")
{ // see if the year field is empty
alert("请先输入年份再计算.");
return false;
}
else if (!isPosInteger(f["day"].value) || f["day"].value == 0)
{
alert("日期值必须为正.");
return false;
}
else if (!isInteger(f["year"].value))
{
alert("年份必须是整数.");
return false;
}
else if ( (f["year"].value < -1000) || (f["year"].value > 3000) )
{
alert("本算法在 -1000 ~ 3000年间适用.");
return false;
}
// For the non-二月 months see if the day entered is greater than
// the number of days in the selected month
else if ((index != 1) && (f["day"].value > monthList[index].numdays))
{
alert("只有 " + monthList[index].numdays + " 天 "
+ monthList[index].name + ".");
return false;
}
// First see if the year entered is a leap year. If so we have to make sure
// the days entered is <= 29. If not a leap year we make sure that the days
// entered is <= 28.
else if (index == 1)
{ // month selected is 二月 the screwball month
if (isLeapYear(f["year"].value)) { // year entered is a leap year
if (f["day"].value > (monthList[index].numdays + 1))
{
alert("There are only " + (monthList[index].numdays + 1)
+ " days in " + monthList[index].name + ".");
return false;
}
else
return true;
}
else
{ // year entered is not a leap year
if (f["day"].value > monthList[index].numdays)
{
alert(monthList[index].name +"只有" +monthList[index].numdays
+ " 天" +"。");
return false;
}
else
return true;
}
}
else
return true;
}
//*********************************************************************/
//convLatLong converts any type of lat/long input
//into the table form and then handles bad input
//it is nested in the calcSun function.
// 将输入的任意类型的经度纬度转换输入到表单中,并且处理无效的输入。
// 嵌套在calcSun函数。
function convLatLong(f)
{
if(f["latDeg"].value == "")
{
f["latDeg"].value = 0;
}
if(f["latMin"].value == "")
{
f["latMin"].value = 0;
}
if(f["latSec"].value == "")
{
f["latSec"].value = 0;
}
if(f["lonDeg"].value == "")
{
f["lonDeg"].value = 0;
}
if(f["lonMin"].value == "")
{
f["lonMin"].value = 0;
}
if(f["lonSec"].value == "")
{
f["lonSec"].value = 0;
}
var neg = 0;
if(f["latDeg"].value.charAt(0) == '-')
{
neg = 1;
}
if(neg != 1)
{
var latSeconds = (parseFloat(f["latDeg"].value))*3600
+ parseFloat(f["latMin"].value)*60
+ parseFloat(f["latSec"].value)*1;
f["latDeg"].value = Math.floor(latSeconds/3600);
f["latMin"].value = Math.floor((latSeconds
- (parseFloat(f["latDeg"].value)*3600))/60);
f["latSec"].value = Math.floor((latSeconds
- (parseFloat(f["latDeg"].value)*3600)
- (parseFloat(f["latMin"].value)*60)) + 0.5);
}
else if(parseFloat(f["latDeg"].value) > -1)
{
var latSeconds = parseFloat(f["latDeg"].value)*3600
- parseFloat(f["latMin"].value)*60
- parseFloat(f["latSec"].value)*1;
f["latDeg"].value = "-0";
f["latMin"].value = Math.floor((-latSeconds)/60);
f["latSec"].value = Math.floor( (-latSeconds
- (parseFloat(f["latMin"].value)*60)) + 0.5);
}
else
{
var latSeconds = parseFloat(f["latDeg"].value)*3600
- parseFloat(f["latMin"].value)*60
- parseFloat(f["latSec"].value)*1;
f["latDeg"].value = Math.ceil(latSeconds/3600);
f["latMin"].value = Math.floor((-latSeconds
+ (parseFloat(f["latDeg"].value)*3600))/60);
f["latSec"].value = Math.floor((-latSeconds
+ (parseFloat(f["latDeg"].value)*3600)
- (parseFloat(f["latMin"].value)*60)) + 0.5);
}
neg = 0;
if(f["lonDeg"].value.charAt(0) == '-')
{
neg = 1;
}
if(neg != 1)
{
var lonSeconds = parseFloat(f["lonDeg"].value)*3600
+ parseFloat(f["lonMin"].value)*60
+ parseFloat(f["lonSec"].value)*1;
f["lonDeg"].value = Math.floor(lonSeconds/3600);
f["lonMin"].value = Math.floor((lonSeconds
- (parseFloat(f["lonDeg"].value)*3600))/60);
f["lonSec"].value = Math.floor((lonSeconds
- (parseFloat(f["lonDeg"].value)*3600)
- (parseFloat(f["lonMin"].value))*60) + 0.5);
}
else if(parseFloat(f["lonDeg"].value) > -1)
{
var lonSeconds = parseFloat(f["lonDeg"].value)*3600
- parseFloat(f["lonMin"].value)*60
- parseFloat(f["lonSec"].value)*1;
f["lonDeg"].value = "-0";
f["lonMin"].value = Math.floor((-lonSeconds)/60);
f["lonSec"].value = Math.floor((-lonSeconds
- (parseFloat(f["lonMin"].value)*60)) + 0.5);
}
else
{
var lonSeconds = parseFloat(f["lonDeg"].value)*3600
- parseFloat(f["lonMin"].value)*60
- parseFloat(f["lonSec"].value)*1;
f["lonDeg"].value = Math.ceil(lonSeconds/3600);
f["lonMin"].value = Math.floor((-lonSeconds
+ (parseFloat(f["lonDeg"].value)*3600))/60);
f["lonSec"].value = Math.floor((-lonSeconds
+ (parseFloat(f["lonDeg"].value)*3600)
- (parseFloat(f["lonMin"].value)*60)) + 0.5);
}
//Test for invalid lat/long input
if(latSeconds > 324000)
{
alert("You have entered an invalid latitude.\n Setting lat = 89.");
f["latDeg"].value = 89;
f["latMin"].value = 0;
f["latSec"].value = 0;
}
if(latSeconds < -324000)
{
alert("You have entered an invalid latitude.\n Setting lat = -89.");
f["latDeg"].value = -89;
f["latMin"].value = 0;
f["latSec"].value = 0;
}
if(lonSeconds > 648000)
{
alert("You have entered an invalid longitude.\n Setting lon = 180.");
f["lonDeg"].value = 180;
f["lonMin"].value = 0;
f["lonSec"].value = 0;
}
if(lonSeconds < -648000)
{
alert("You have entered an invalid longitude.\n Setting lon = -180.");
f["lonDeg"].value = -180;
f["lonMin"].value = 0;
f["lonSec"].value =0;
}
}
//***********************************************************************/
//***********************************************************************/
//* */
//*This section contains subroutines used in calculating solar position */
//* */
//***********************************************************************/
//***********************************************************************/
// Convert radian angle to degrees
// 将弧度转为度数。
function radToDeg(angleRad)
{
return (180.0 * angleRad / Math.PI);
}
//*********************************************************************/
// Convert degree angle to radians
// 将度数转换为弧度。
function degToRad(angleDeg)
{
return (Math.PI * angleDeg / 180.0);
}
//*********************************************************************/
//***********************************************************************/
//* Name: calcDayOfYear */
//* Type: Function */
//* Purpose: Finds numerical day-of-year from mn, day and lp year info */
//* Arguments: */
//* month: 一月 = 1 */
//* day : 1 - 31 */
//* lpyr : 1 if leap year, 0 if not */
//* Return value: */
//* The numerical day of year */
//***********************************************************************/
// 根据月份、天数和是否为闰年计算是否为闰年。
function calcDayOfYear(mn, dy, lpyr)
{
var k = (lpyr ? 1 : 2);
var doy = Math.floor((275 * mn)/9) - k * Math.floor((mn + 9)/12) + dy -30;
return doy;
}
//***********************************************************************/
//* Name: calcDayOfWeek */
//* Type: Function */
//* Purpose: Derives weekday from Julian Day */
//* Arguments: */
//* juld : Julian Day */
//* Return value: */
//* String containing name of weekday */
//***********************************************************************/
// 使用儒略日计算星期名称。
function calcDayOfWeek(juld)
{
var A = (juld + 1.5) % 7;
var DOW = (A==0)?"Sunday":(A==1)?"Monday":(A==2)?"Tuesday":(A==3)?"Wednesday":(A==4)?"Thursday":(A==5)?"Friday":"Saturday";
return DOW;
}
//***********************************************************************/
//* Name: calcJD */
//* Type: Function */
//* Purpose: Julian day from calendar day */
//* Arguments: */
//* year : 4 digit year */
//* month: 一月 = 1 */
//* day : 1 - 31 */
//* Return value: */
//* The Julian day corresponding to the date */
//* Note: */
//* Number is returned for start of day. Fractional days should be */
//* added later. */
//***********************************************************************/
// 通过历日计算儒略日。
function calcJD(year, month, day)
{
if (month <= 2) {
year -= 1;
month += 12;
}
var A = Math.floor(year/100);
var B = 2 - A + Math.floor(A/4);
var JD = Math.floor(365.25*(year + 4716)) + Math.floor(30.6001*(month+1)) + day + B - 1524.5;
return JD;
}
//***********************************************************************/
//* Name: calcDateFromJD */
//* Type: Function */
//* Purpose: Calendar date from Julian Day */
//* Arguments: */
//* jd : Julian Day */
//* Return value: */
//* String date in the form DD-MONTHNAME-YYYY */
//* Note: */
//***********************************************************************/
// 通过天略日计算日期。
function calcDateFromJD(jd)
{
var z = Math.floor(jd + 0.5);
var f = (jd + 0.5) - z;
if (z < 2299161) {
var A = z;
} else {
alpha = Math.floor((z - 1867216.25)/36524.25);
var A = z + 1 + alpha - Math.floor(alpha/4);
}
var B = A + 1524;
var C = Math.floor((B - 122.1)/365.25);
var D = Math.floor(365.25 * C);
var E = Math.floor((B - D)/30.6001);
var day = B - D - Math.floor(30.6001 * E) + f;
var month = (E < 14) ? E - 1 : E - 13;
var year = (month > 2) ? C - 4716 : C - 4715;
// alert ("date: " + day + "-" + monthList[month-1].name + "-" + year);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -