-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcjdn.html
82 lines (71 loc) · 2.41 KB
/
calcjdn.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!doctype html>
<head>
<meta charset="utf-8">
<title>Julian Date</title>
</head>
<body>
Input date Firefox dd.mm.yyyy, Safari yyyy.mm.dd<br>
<input id="datein" type="date" required pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}"><p>
Input UTC time<br>
<input id="timein" type="time" required pattern="[0-9]{2}:[0-9]{2}">
<p id="demo">JD Calculation of the given date</p>
<button onClick="calculate()">Calculate</button>
<script>
function myInit(){
let dateObj = new Date();
let month = dateObj.getUTCMonth() + 1; //months from 1-12
let day = dateObj.getUTCDate();
let year = dateObj.getUTCFullYear();
let hour = dateObj.getHours();
let mins = dateObj.getMinutes();
let tzone = dateObj.getTimezoneOffset()/-60;
var prezero = function(n) {
//let zfill = "";
((n < 0) ? n += 24 : n);
return ((n < 10) ? "0" : "") + n;
}
let today = year + "-" + prezero(month) + "-" + prezero(day);
let now = prezero(hour - tzone) + ":" + prezero(mins);
console.log(today);
console.log("UTC time: %s = Local %2d:%2d UTC+%3d", now, hour, mins, tzone);
document.getElementById("demo").innerHTML = today;
document.getElementById("datein").value = today;
document.getElementById("timein").value = now;
}
myInit();
function calculate() {
let dvalue = document.getElementById("datein").value;
let A = Array(3);
let B = Array(2);
if (dvalue.indexOf("-") > 0) { A = dvalue.split("-");}
else {A = dvalue.split(".")};
let [year, month, day] = A.map(i => Number(i));
console.log("Date:", day, month, year);
let jdate = jdncalc(day, month, year);
console.log("JDN Gregorian calendar", jdate);
B = timein.value.split(":");
[hrs, mns] = B.map(n => Number(n));
console.log("Time UTC", timein.value);
let jtime = jdcalc(jdate, hrs, mns);
console.log("JD = %12.4f at UTC %2d:%2d", jtime, hrs, mns);
document.getElementById("demo").innerHTML
= `Date ${year}-${month}-${day} Julian Day Number JDN = ${jdate}`
+ `<br>JD = ${jtime.toFixed(4)} at UTC ` + timein.value;
}
const jdcalc = function(jd, hour, minute) {
return jd + (hour - 12)/24 + minute/1440;
}
const jdncalc = function(D, M, Y) {
"use strict";
console.log("Laskentapvm", Y, M, D);
let quot = (y, x) => Math.floor(y/x);
let a = quot(14 - M, 12);
let y = Y + 4800 - a;
let m = M + 12*a - 3;
let JDN = D + quot(153*m + 2, 5) + 365*y + quot(y, 4)
- quot(y,100) + quot(y, 400) - 32045;
return JDN
}
</script>
</body>
</html>