-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathJulian_c.js
executable file
·1 lines (1 loc) · 14.8 KB
/
Julian_c.js
1
"use strict";function header(e,t,n){let l,a=[];0==e?(l={id:"menuconversion",title:"Calendar<br />Conversion"},l.sub=[{title:"Yearly Calendar",url:"index.html"},{title:"Conversion Table",url:"table.html"},{title:"Sun & Moon Phenomena",url:"sunMoon.html"},{title:"Julian & Sexagenary Date Calculator",url:"Julian.html"}],a.push(l),l={id:"menuCalendarBasics",title:"Chinese Calendar<br />Basics"},l.sub=[{title:"24 Solar Terms",url:"solarTerms.html"},{title:"Sexagenary Cycle",url:"sexagenary.html"},{title:"Chinese Calendar Rules",url:"rules.html"},{title:"Calendar Quiz",url:"simpleQuiz.html"}],a.push(l),l={id:"menuCalendarComputation",title:"Calendar<br />Computation"},l.sub=[{title:"Chinese Calendar Generation",url:"computation.html"},{title:"Moon Phases and Solar Terms",url:"docs/sunMoon.pdf"},{title:"Chunqiu Calendar",url:"chunqiu.html"},{title:"Ancient Six Calendars",url:"guliuli.html"},{title:"Qin & Early Han Calendars",url:"QinHanCalendars.html"}],a.push(l),l={id:"menuMisc",title:"Other<br />Links"},l.sub=[{title:"Miscellaneous",url:"others.html"},{title:"FAQ",url:"faq.html"}],a.push(l)):1==e?(l={id:"menuconversion",title:"中 西 曆 對 照"},l.sub=[{title:"年曆",url:"index_chinese.html"},{title:"朔閏表",url:"table_chinese.html"},{title:"氣朔時刻",url:"sunMoon_chinese.html"},{title:"中國歷史年表",url:"era_names.html"},{title:"儒略日數和日干支計算器",url:"Julian_chinese.html"}],a.push(l),l={id:"menuCalendarBasics",title:"農 曆 知 識"},l.sub=[{title:"二十四節氣",url:"solarTerms_chinese.html"},{title:"六十干支",url:"sexagenary_chinese.html"},{title:"農曆編算法則",url:"rules_chinese.html"},{title:"曆法測驗",url:"simpleQuiz_chinese.html"}],a.push(l),l={id:"menuCalendarComputation",title:"曆 法 計 算"},l.sub=[{title:"編算農曆",url:"computation_chinese.html"},{title:"月相和二十四節氣算法",url:"docs/sunMoon_chinese.pdf"},{title:"春秋曆復原法",url:"chunqiu_chinese.html"},{title:"古六曆計算法",url:"guliuli_chinese.html"},{title:"秦至漢初的曆法復原",url:"QinHanCalendars_chinese.html"}],a.push(l),l={id:"menuMisc",title:"其 他"},l.sub=[{title:"雜 項",url:"others_chinese.html"},{title:"常見問題",url:"faq_chinese.html"}],a.push(l)):(l={id:"menuconversion",title:"中 西 历 对 照"},l.sub=[{title:"年历",url:"index_simp.html"},{title:"朔闰表",url:"table_simp.html"},{title:"气朔时刻",url:"sunMoon_simp.html"},{title:"中国历史年表",url:"era_names_simp.html"},{title:"儒略日数和日干支计算器",url:"Julian_simp.html"}],a.push(l),l={id:"menuCalendarBasics",title:"农 历 知 识"},l.sub=[{title:"二十四节气",url:"solarTerms_simp.html"},{title:"六十干支",url:"sexagenary_simp.html"},{title:"农历编算法则",url:"rules_simp.html"},{title:"历法测验",url:"simpleQuiz_simp.html"}],a.push(l),l={id:"menuCalendarComputation",title:"历 法 计 算"},l.sub=[{title:"编算农历",url:"computation_simp.html"},{title:"月相和二十四节气算法",url:"docs/sunMoon_simp.pdf"},{title:"春秋历复原法",url:"chunqiu_simp.html"},{title:"古六历计算法",url:"guliuli_simp.html"},{title:"秦至汉初的历法复原",url:"QinHanCalendars_simp.html"}],a.push(l),l={id:"menuMisc",title:"其 他"},l.sub=[{title:"杂项",url:"others_simp.html"},{title:"常见问题",url:"faq_simp.html"}],a.push(l));let o='<div class="menu">';a.forEach((function(e){o+='<div class="dropdown" id="'+e.id+'">';let t=e.sub.length;if(0==t)o+='<button class="dropbtn" style="cursor:pointer;" onclick="myloadurl(\''+e.url+"')\">"+e.title+"</button></div>";else{o+='<button class="dropbtn" onclick="display_dropdown_menu(\''+e.id+"')\">"+e.title+"</button>",o+='<div class="dropdown-content">';for(let n=0;n<t;n++)o+="<p onclick=\"myloadurl('"+e.sub[n].url+"')\">"+e.sub[n].title+"</p>";o+="</div></div>"}})),o+="</div>",document.getElementById("menu").innerHTML=o,""!=n&&(o='<h2 style="text-align:right;">',o+=0==e?'Chinese versions: <a href="'+n+'_chinese.html">傳統中文</a> <a href="'+n+'_simp.html">简体中文</a></h2>':1==e?'<a href="'+n+'.html">English 英文</a> <a href="'+n+'_simp.html">简体中文</a></h2>':'<a href="'+n+'.html">English 英文</a> <a href="'+n+'_chinese.html">傳統中文</a></h2>',document.getElementById("language").innerHTML=o),window.location!==window.parent.location&&("table"==t?""==n?document.getElementById("table").style.display=none:document.getElementById("mainMenu").style.display=none:document.getElementById("wrapper0").style.display=none),add_footer()}function display_dropdown_menu(e){document.getElementById(e).classList.toggle("showdropdown");let t=document.getElementsByClassName("showdropdown"),n=t.length;for(let l=0;l<n;l++)if(t[l].id!=e){t[l].classList.remove("showdropdown");break}}function myloadurl(e){let t=document.getElementsByClassName("showdropdown");1==t.length&&t[0].classList.remove("showdropdown"),location.href=e}function add_footer(){let e=document.createElement("FOOTER");e.innerHTML='<hr /><p style="text-align:center;font-size:90%;">© 2018–2025 Yuk Tung Liu</p>',document.body.appendChild(e)}function exception_handler(){let e=document.createElement("FOOTER");e.innerHTML="<h1>Secure Connection Failed</h1>",document.body.appendChild(e)}function init(e){if(window.location===window.parent.location){document.getElementById("wrapper0").style.display="block",header(e,"","Julian");let t=new Date,n=t.getFullYear(),l=t.getMonth()+1,a=t.getDate(),o=12,r=0,u=0;document.getElementById("midnight").checked=!1,document.getElementById("noon").checked=!0,document.getElementById("custom").checked=!1,document.getElementById("year").value=n,document.getElementById("month").value=l,document.getElementById("date").value=a,document.getElementById("hour").value=o,document.getElementById("minute").value=r,document.getElementById("second").value=u,document.getElementById("hour").disabled=!0,document.getElementById("minute").disabled=!0,document.getElementById("second").disabled=!0,getJDSexagenary(e,document.getElementById("calendarDate"));let i=document.getElementById("JD");i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("JDBtn").click())})),i=document.getElementById("year"),i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("tabBtn").click())})),i=document.getElementById("month"),i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("tabBtn").click())})),i=document.getElementById("date"),i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("tabBtn").click())})),i=document.getElementById("hour"),i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("tabBtn").click())})),i=document.getElementById("minute"),i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("tabBtn").click())})),i=document.getElementById("second"),i.addEventListener("keyup",(function(e){"Enter"===e.key&&(e.preventDefault(),document.getElementById("tabBtn").click())}))}else exception_handler()}function changeInputTime(e,t){0==(t=parseInt(t,10))||12==t?(document.getElementById("hour").value=t,document.getElementById("minute").value=0,document.getElementById("second").value=0,document.getElementById("hour").disabled=!0,document.getElementById("minute").disabled=!0,document.getElementById("second").disabled=!0):(document.getElementById("hour").disabled=!1,document.getElementById("minute").disabled=!1,document.getElementById("second").disabled=!1),""==document.getElementById("err").innerHTML&&getJDSexagenary(e,document.getElementById("calendarDate"))}function getJDSexagenary(e,t){document.getElementById("err").innerHTML="",document.getElementById("output").innerHTML="";let n="err",l=parseInt(t.year.value,10),a=parseInt(t.year.min,10),o=parseInt(t.year.max,10),r=["Year","年份","年份"],u=generate_message(e,r[e],a,o);sanityCheck(l,"year",a,o,u,n);let i=parseInt(t.month.value,10);a=parseInt(t.month.min,10),o=parseInt(t.month.max,10),r=["Month","月份","月份"],u=generate_message(e,r[e],a,o),sanityCheck(i,"month",a,o,u,n);let d=parseInt(t.date.value,10);a=parseInt(t.date.min,10),o=parseInt(t.date.max,10),r=["Date","日期","日期"],u=generate_message(e,r[e],a,o),sanityCheck(d,"date",a,o,u,n);let m=parseInt(t.hour.value,10);a=parseInt(t.hour.min,10),o=parseInt(t.hour.max,10),r=["Hour","小時","小时"],u=generate_message(e,r[e],a,o),sanityCheck(m,"hour",a,o,u,n);let s=parseInt(t.minute.value,10);a=parseInt(t.minute.min,10),o=parseInt(t.minute.max,10),r=["Minute","分鐘","分钟"],u=generate_message(e,r[e],a,o),sanityCheck(s,"minute",a,o,u,n);let c=parseInt(t.second.value,10);if(a=parseInt(t.second.min,10),o=parseInt(t.second.max,10),r=["Second","秒的","秒的"],u=generate_message(e,r[e],a,o),sanityCheck(c,"second",a,o,u,n),""==document.getElementById("err").innerHTML){1582==l&&10==i&&d>4&&d<15&&(d+=10);let t=getJDnoon(l,i,d);write_output(e,t,t+(m/24+s/1440+c/86400-.5)),document.getElementById("JD").style.backgroundColor="transparent"}}function JDtoCalendar(e){document.getElementById("err").innerHTML="",document.getElementById("output").innerHTML="";let t,n=parseFloat(document.getElementById("JD").value),l=5373850.499988,a=-1931442.5;if(t=0==e?"Invalid Julian date input! Please enter a number between "+a+" and "+l+".":1==e?"儒略日數輸入錯誤!請輸入在 "+a+" 和 "+l+" 之間的數字。":"儒略日数输入错误!请输入在 "+a+" 和 "+l+" 之间的数字。",sanityCheck(n,"JD",a,l,t,"err"),""==document.getElementById("err").innerHTML){write_output(e,Math.floor(n+.5),n),["year","month","date","hour","minute","second"].forEach((e=>document.getElementById(e).style.backgroundColor="transparent"))}}function generate_message(e,t,n,l){let a;return a=0==e?"Invalid "+t+" input! Please input a number between "+n+" and "+l+".":1==e?t+"輸入錯誤!請輸入包括 "+n+" 和 "+l+" 之間的整數。":t+"输入错误!请输入包括 "+n+" 和 "+l+" 之间的整数。",a}function write_output(e,t,n){let l=parseFloat(n.toFixed(6));document.getElementById("JD").value=l;let a=CalDat(n),o=langConstant(e),r=a.yy,u=a.mm,i=a.dd,d=a.h,m=a.m,s=a.s,c=document.getElementById("calendarDate");c.year.value=r,c.month.value=u,c.date.value=i,c.hour.value=d,c.minute.value=m,c.second.value=s;let h,p,y,g=document.getElementById("noon"),b=document.getElementById("midnight"),E=document.getElementById("custom");0==d&&0==m&&0==s?g.checked&&(g.checked=!1,b.checked=!0):12==d&&0==m&&0==s?b.checked&&(b.checked=!1,g.checked=!0):(b.checked||g.checked)&&(b.checked=!1,g.checked=!1,E.checked=!0,document.getElementById("hour").disabled=!1,document.getElementById("minute").disabled=!1,document.getElementById("second").disabled=!1);let f=(t+1)%7;f<0&&(f+=7);let I=(t-11)%60;I<0&&(I+=60);let B=I%10,M=I%12;0==e?(h='<br /><h3><u>Result</u></h3><p style="color:blue;">',p="Date in "+(t>2299160?"Gregorian ":r<8?"Proleptic Julian":"Julian")+" calendar: ",y=r>0?r+" CE":1-r+" BCE",h+=p+i+" "+o.gMonth[u-1]+", "+y,h+=" Time: "+a.timeString+"</p>",h+='<p style="color:blue;">Julian date = '+l+" day of week: ",h+=o.weeks[f]+"</p>",h+='<p style="color:blue;">Sexagenary date: '+o.heaven[B]+" "+o.earth[M]+" (sexagenary number = "+(I+1)+")</p>"):1==e?(h='<br /><h3><u>計 算 結 果</u></h3><p style="color:blue;">',p="公曆日期: ",y=(r>0?"公元"+r:"公元前"+(1-r))+"年",h+=p+y+u+"月"+i+"日",h+=", 時間: "+a.timeString+"</p>",h+='<p style="color:blue;">儒略日數:'+l+", ",h+=o.weeks[f]+"</p>",h+='<p style="color:blue;">日干支: '+o.heaven[B]+o.earth[M]+"(干支數="+(I+1)+")</p>"):(h='<br /><h3><u>计 算 结 果</u></h3><p style="color:blue;">',p="公历日期: ",y=(r>0?"公元"+r:"公元前"+(1-r))+"年",h+=p+y+u+"月"+i+"日",h+=", 时间: "+a.timeString+"</p>",h+='<p style="color:blue;">儒略日数:'+l+", ",h+=o.weeks[f]+"</p>",h+='<p style="color:blue;">日干支: '+o.heaven[B]+o.earth[M]+"(干支数="+(I+1)+")</p>"),document.getElementById("output").innerHTML=h}function getJDnoon(e,t,n){let l,a=t,o=e;return a<=2&&(a+=12,o--),l=1e4*o+100*a+n<=15821004?-2+Math.floor((o+4716)/4)-1179:Math.floor(o/400)-Math.floor(o/100)+Math.floor(o/4),365*o-679004+l+Math.floor(30.6001*(a+1))+n+2400001}function CalDat(e){let t,n,l,a,o,r,u=e+.5/86400;if(t=Math.floor(u+.5),t<0)return CalDatNegativeJD(u);t<2299161?(n=0,l=t+1524):(n=Math.floor((t-1867216.25)/36524.25),l=t+n-Math.floor(.25*n)+1525),a=Math.floor((l-122.1)/365.25),a<0&&a++,o=365*a+Math.floor(.25*a),r=Math.floor((l-o)/30.6001),r<0&&r++;let i=l-o-Math.floor(30.6001*r),d=r-1-12*Math.floor(r/14+1e-5),m=a-4715-Math.floor((7+d)/10+1e-5),s=generateDateString(m,d,i),c=24*(u-Math.floor(u+.5)+.5),h=Math.floor(c),p=Math.floor(60*(c-h)),y=Math.floor(3600*(c-h-p/60));return{yy:m,mm:d,dd:i,h:h,m:p,s:y,dateString:s,timeString:generateTimeString(h,p,y)}}function CalDatNegativeJD(e){let t,n,l,a,o=e+.5/86400,r=-Math.floor(o+.5),u=r-Math.floor(r/1461),i=Math.floor(u/(365+1e-10))+1,d=-4712-i,m=365*i+Math.floor(i/4)+1-r;for(t=i%4==0?[0,31,60,91,121,152,182,213,244,274,305,335,366]:[0,31,59,90,120,151,181,212,243,273,304,334,365],n=1;n<13;n++)if(m<=t[n]){l=n,a=m-t[n-1];break}let s=generateDateString(d,l,a),c=24*(.5+(o+r)),h=Math.floor(c),p=Math.floor(60*(c-h)),y=Math.floor(3600*(c-h-p/60));return{yy:d,mm:l,dd:a,h:h,m:p,s:y,dateString:s,timeString:generateTimeString(h,p,y)}}function generateDateString(e,t,n){let l=Math.abs(e);l=l<10?"000"+l:l<100?"00"+l:l<1e3?"0"+l:l.toString();let a=l;e<0&&(a="-"+a);let o=t.toString();t<10&&(o="0"+o);let r=n.toString();return n<10&&(r="0"+r),a+"-"+o+"-"+r}function generateTimeString(e,t,n){let l=e+t/60+(n+.5)/3600,a=Math.floor(l),o=Math.floor(60*(l-a)),r=Math.floor(3600*(l-a-o/60));return a=a.toString(),o=o.toString(),r=r.toString(),a.length<2&&(a="0"+a),o.length<2&&(o="0"+o),r.length<2&&(r="0"+r),a+":"+o+":"+r}function langConstant(e){let t,n,l,a;return 0==e?(t=["January","February","March","April","May","June","July","August","September","October","November","December"],n=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],l=["Jiǎ","Yǐ","Bǐng","Dīng","Wù","Jǐ","Gēng","Xīn","Rén","Guǐ"],a=["zǐ","chǒu","yín","mǎo","chén","sì","wǔ","wèi","shēn","yǒu","xū","hài"]):(t=["1 月;","2 月","3 月","4 月","5 月","6 月","7 月","8 月","9 月","10 月","11 月","12 月"],n=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],l=["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],a=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]),{gMonth:t,weeks:n,lang:e,heaven:l,earth:a}}function sanityCheck(e,t,n,l,a,o){if(document.getElementById(t).style.backgroundColor="transparent",isNaN(e)||e<n||e>l){document.getElementById(t).style.backgroundColor="#e2a8a8";let e='<p style="color:red;">'+a+"</p>";document.getElementById(o).innerHTML+=e}}