Skip to content

Commit

Permalink
add julian calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
YingChangJ committed May 1, 2024
1 parent 5112bcb commit 4b93207
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions javascript/julian.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ function updateTime() {
date.setUTCFullYear(yearForCal);
date.setUTCHours(date.getUTCHours() - timeZoneForCal);
const astroTime = new Astronomy.AstroTime(date);
console.log(astroTime);

utInput.value = (astroTime.ut + 2451545.0).toFixed(6);
ttInput.value = (astroTime.tt + 2451545.0).toFixed(6);
tsInput.value = +date;
tssInput.value = Math.floor(date / 1000);
jde.innerHTML = `JDE (J2000): ${astroTime.tt.toFixed(6)}`;
jde.innerHTML = `
Julian Calendar(UTC): ${jd2JulianCalendar(astroTime.ut + 2451545.0)}
<br>JDE (J2000): ${astroTime.tt.toFixed(6)}`;
}

function updateTimeFromTT() {
Expand All @@ -101,7 +103,10 @@ function updateTimeFromTT() {
tt.value = astroTime.tt + 2451545.0;
ts.value = +dateNew;
tss.value = Math.floor(+dateNew / 1000);
jde.innerHTML = `JDE (J2000): ${astroTime.tt.toFixed(6)}`;
jde.innerHTML = `Julian Calendar(UTC): ${jd2JulianCalendar(
astroTime.ut + 2451545.0
)}
<br>JDE (J2000): ${astroTime.tt.toFixed(6)}`;
}

function updateTimeFromUT() {
Expand All @@ -119,7 +124,10 @@ function updateTimeFromUT() {
tt.value = astroTime.tt + 2451545.0;
ts.value = +dateNew;
tss.value = Math.floor(+dateNew / 1000);
jde.innerHTML = `JDE (J2000): ${astroTime.tt.toFixed(6)}`;
jde.innerHTML = `Julian Calendar(UTC): ${jd2JulianCalendar(
astroTime.ut + 2451545.0
)}
<br>JDE (J2000): ${astroTime.tt.toFixed(6)}`;
}

function updateTimeFromTS() {
Expand All @@ -135,7 +143,10 @@ function updateTimeFromTS() {
ut.value = astroTime.ut + 2451545.0;
tt.value = astroTime.tt + 2451545.0;
tss.value = Math.floor(ts.value / 1000);
jde.innerHTML = `JDE (J2000): ${astroTime.tt.toFixed(6)}`;
jde.innerHTML = `Julian Calendar(UTC): ${jd2JulianCalendar(
astroTime.ut + 2451545.0
)}
<br>JDE (J2000): ${astroTime.tt.toFixed(6)}`;
}
function updateTimeFromTSSec() {
const dateNew = new Date(Number(tss.value) * 1000);
Expand All @@ -150,7 +161,33 @@ function updateTimeFromTSSec() {
ut.value = astroTime.ut + 2451545.0;
tt.value = astroTime.tt + 2451545.0;
ts.value = Number(tss.value) * 1000;
jde.innerHTML = `Julian Calendar(UTC): ${jd2JulianCalendar(
astroTime.ut + 2451545.0
)}
<br>JDE (J2000): ${astroTime.tt.toFixed(6)}`;
}
//method from swisseph: swe_revjul
function jd2JulianCalendar(jd, includeHour = true) {
const u0 = jd + 32082.5;
const u2 = Math.floor(u0 + 123.0);
const u3 = Math.floor((u2 - 122.2) / 365.25);
const u4 = Math.floor((u2 - Math.floor(365.25 * u3)) / 30.6001);
let month = u4 - 1;
if (month > 12) month -= 12;
const day = u2 - Math.floor(365.25 * u3) - Math.floor(30.6001 * u4);
const year = u3 + Math.floor((u4 - 2.0) / 12.0) - 4800;
if (includeHour) {
const hour = (jd - Math.floor(jd + 0.5) + 0.5) * 24.0;
const hour_int = Math.floor(hour);
const minute = Math.floor((hour % 1) * 60);
const second = ((hour * 60) % 1) * 60;
return `${year}-${month}-${day} ${hour_int}:${minute}:${Math.floor(
second
)}`;
}
return `${year}-${month}-${day}`;
}

//logic about the date and time input
const nextThreshold = [1680, 2, 4, 3, 6, 6];
const maxValue = [16800, 12, 31, 24, 59, 59];
Expand Down

0 comments on commit 4b93207

Please sign in to comment.