-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateTimePanel.js
433 lines (433 loc) · 13.4 KB
/
DateTimePanel.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
"use strict";
//http://www.htmldockfloat.com/demo/JavaScriptDockFloatSimpleDemo.html
//addLanguageChangeHandle(function(code){console.log("language change: "+code)});
function setSelectDate(select_element, days) {
var noptdays = select_element.options.length;
if (noptdays < days) {
var doc = select_element.ownerDocument;
while (select_element.options.length < days) {
var opt = doc.createElement("option");
opt.text = (select_element.options.length + 1).toString();
if (select_element.add.length === 2) {
select_element.add(opt, null); // standards compliant
}
else {
select_element.add(opt); // IE only
}
}
doc = null;
}
else if (noptdays > days) {
while (select_element.options.length > days) {
select_element.options.remove(select_element.options.length - 1);
}
}
}
function initDateTimePanel() {
DOM$.select.fillRange("UTCDate", 1, 31);
DOM$.select.fillRange("UTCHours", 0, 23);
DOM$.select.fillRange("UTCMinutes", 0, 59);
DOM$.select.fillRange("UTCSeconds", 0, 59);
DOM$.select.fillRange("LocalDate", 1, 31);
DOM$.select.fillRange("LocalHours", 0, 23);
DOM$.select.fillRange("LocalMinutes", 0, 59);
DOM$.select.fillRange("LocalSeconds", 0, 59);
}
var dateUTC = new DateTimeTick(), dateTAI, dateTT, dateTCG;
dateUTC.setStartAction(function () {
DOM$.c("RunStop")[0].value = "Stop";
// DOM$.c("RunStop")[1].value = "Stop";
});
dateUTC.setStopAction(function () {
DOM$.c("RunStop")[0].value = "Run";
// DOM$.c("RunStop")[1].value = "Run";
});
//alert(dateUTC.oldMethods.getFullYear());
/***********************************************************************
Time Scales conversion
***********************************************************************/
function setFromUTC() {
dateTAI = dateUTC.copy();
dateTAI.UTCtoTAI();
dateTT = dateTAI.copy();
dateTT.TAItoTT();
dateTCG = dateTT.copy();
dateTCG.TTtoTCG();
}
function setFromTAI() {
dateUTC = dateTAI.copy();
dateUTC.TAItoUTC();
dateTT = dateTAI.copy();
dateTT.TAItoTT();
dateTCG = dateTT.copy();
dateTCG.TTtoTCG();
}
function setFromTT() {
dateTAI = dateTT.copy();
dateTAI.TTtoTAI();
dateUTC = dateTAI.copy();
dateUTC.TAItoUTC();
dateTCG = dateTT.copy();
dateTCG.TTtoTCG();
}
function setFromTCG() {
dateTT = dateTCG.copy();
dateTT.TCGtoTT();
dateTAI = dateTT.copy();
dateTAI.TTtoTAI();
dateUTC = dateTAI.copy();
dateUTC.TAItoUTC();
}
var panelRefreshActions = [];
function addPanelRefreshAction(func) {
panelRefreshActions.push(func);
}
function updateDateTimePanel() {
DOM$.i("UTCString").innerHTML = dateUTC.toUTCString();
DOM$.i("UTCYear").value =
(dateUTC.getUTCFullYear() <= 0) ?
(-dateUTC.getUTCFullYear() + 1).toString() :
dateUTC.getUTCFullYear().toString();
DOM$.i("UTCEra").selectedIndex = (dateUTC.getUTCFullYear() <= 0) ? 0 : 1;
DOM$.i("UTCLeapYear").checked = dateUTC.isUTCLeapYear();
DOM$.i("UTCMonth").selectedIndex = dateUTC.getUTCMonth();
setSelectDate(DOM$.i("UTCDate"), dateUTC.getUTCMonthDays());
DOM$.i("UTCDate").value = dateUTC.getUTCDate();
DOM$.i("UTCDay").selectedIndex = dateUTC.getUTCDay();
DOM$.i("UTCHours").value = dateUTC.getUTCHours();
DOM$.i("UTCMinutes").value = dateUTC.getUTCMinutes();
DOM$.i("UTCSeconds").value = dateUTC.getUTCSeconds();
DOM$.i("UTCMilliseconds").value = dateUTC.getUTCMilliseconds().toString().padStart(3, '0');
DOM$.i("JulianDate").value = Number(dateUTC.getJulianDate()).toFixed(10);
DOM$.i("LocalString").innerHTML = dateUTC.toString();
DOM$.i("LocalYear").value =
(dateUTC.getFullYear() <= 0) ?
(-dateUTC.getFullYear() + 1).toString() :
dateUTC.getFullYear().toString();
DOM$.i("LocalEra").selectedIndex = (dateUTC.getFullYear() <= 0) ? 0 : 1;
DOM$.i("LocalLeapYear").checked = dateUTC.isLocalLeapYear();
DOM$.i("LocalMonth").selectedIndex = dateUTC.getMonth();
setSelectDate(DOM$.i("LocalDate"), dateUTC.getLocalMonthDays());
DOM$.i("LocalDate").value = dateUTC.getDate();
DOM$.i("LocalDay").selectedIndex = dateUTC.getLocalDay();
DOM$.i("LocalHours").value = dateUTC.getHours();
DOM$.i("LocalMinutes").value = dateUTC.getMinutes();
DOM$.i("LocalSeconds").value = dateUTC.getSeconds();
DOM$.i("LocalMilliseconds").value = dateUTC.getMilliseconds().toString().padStart(3, '0');
DOM$.i("DaylightSavingTime").checked = dateUTC.isDST();
DOM$.i("DaylightSavingTime").disabled = dateUTC.getIsLocal();
DOM$.i("TimezoneAdjust").value = dateUTC.getTimezoneOffset();
for (var i = 0; i < panelRefreshActions.length; i++) {
panelRefreshActions[i]();
}
}
function getStepPanelValue() {
if (DOM$.i("sYear").checked) {
return 6;
}
else if (DOM$.i("sMonth").checked) {
return 5;
}
else if (DOM$.i("sDay").checked) {
return 4;
}
else if (DOM$.i("sHours").checked) {
return 3;
}
else if (DOM$.i("sMinutes").checked) {
return 2;
}
else if (DOM$.i("sSeconds").checked) {
return 1;
}
else {
return 0;
}
}
function changeStepPanelValue() {
dateUTC.setStepDateTime(getStepPanelValue());
}
function panelUpdate(date) {
setFromUTC();
updateDateTimePanel();
// updateEphemerisPanel();
// UpdateScreen();
}
//dateUTC.runAction = panelUpdate;
dateUTC.setRunAction(panelUpdate);
/***********************************************************************
DateTime Panel element events (click, change, ...)
***********************************************************************/
function clickNow() {
dateUTC.stop();
dateUTC.setNow();
panelUpdate(dateUTC);
}
var clickRunStop = dateUTC.runStop;
function clickSetRunModeNow(isNow) {
dateUTC.setRunModeNow(isNow, isNow ? 250 : 1000, 1, getStepPanelValue());
}
/***********************************************************************
Change UTC DateTime Panel
***********************************************************************/
function changeUTCYear() {
dateUTC.stop();
dateUTC.setUTCFullYear(DOM$.i("UTCYear").value);
panelUpdate(dateUTC);
}
function changeUTCEra() {
dateUTC.stop();
var d = Math.abs(dateUTC.getUTCFullYear());
dateUTC.setUTCFullYear((DOM$.i("UTCEra").selectedIndex ? 1 : -1) * d);
panelUpdate(dateUTC);
}
function changeUTCMonth() {
dateUTC.stop();
dateUTC.setUTCMonth(DOM$.i("UTCMonth").selectedIndex);
panelUpdate(dateUTC);
}
function changeUTCDate() {
dateUTC.stop();
dateUTC.setUTCDate(DOM$.i("UTCDate").selectedIndex + 1);
panelUpdate(dateUTC);
}
function changeUTCHours() {
dateUTC.stop();
dateUTC.setUTCHours(DOM$.i("UTCHours").selectedIndex);
panelUpdate(dateUTC);
}
function changeUTCMinutes() {
dateUTC.stop();
dateUTC.setUTCMinutes(DOM$.i("UTCMinutes").selectedIndex);
panelUpdate(dateUTC);
}
function changeUTCSeconds() {
dateUTC.stop();
dateUTC.setUTCSeconds(DOM$.i("UTCSeconds").selectedIndex);
panelUpdate(dateUTC);
}
function changeUTCMilliseconds() {
dateUTC.stop();
dateUTC.setUTCMilliseconds(DOM$.i("UTCMilliseconds").value);
panelUpdate(dateUTC);
}
/***********************************************************************
Change Local DateTime Panel
***********************************************************************/
function changeLocalYear() {
dateUTC.stop();
dateUTC.setFullYear(DOM$.i("LocalYear").value);
panelUpdate(dateUTC);
}
function changeLocalEra() {
dateUTC.stop();
var d = Math.abs(dateUTC.getLocalFullYear());
dateUTC.setFullYear((DOM$.i("LocalEra").selectedIndex ? 1 : -1) * d);
panelUpdate(dateUTC);
}
function changeLocalMonth() {
dateUTC.stop();
dateUTC.setMonth(DOM$.i("LocalMonth").selectedIndex);
panelUpdate(dateUTC);
}
function changeLocalDate() {
dateUTC.stop();
dateUTC.setDate(DOM$.i("LocalDate").selectedIndex + 1);
panelUpdate(dateUTC);
}
function changeLocalHours() {
dateUTC.stop();
dateUTC.setHours(DOM$.i("LocalHours").selectedIndex);
panelUpdate(dateUTC);
}
function changeLocalMinutes() {
dateUTC.stop();
dateUTC.setMinutes(DOM$.i("LocalMinutes").selectedIndex);
panelUpdate(dateUTC);
}
function changeLocalSeconds() {
dateUTC.stop();
dateUTC.setSeconds(DOM$.i("LocalSeconds").selectedIndex);
panelUpdate(dateUTC);
}
function changeLocalMilliseconds() {
dateUTC.stop();
dateUTC.setMilliseconds(DOM$.i("LocalMilliseconds").value);
panelUpdate(dateUTC);
}
function changeTZAdjust() {
dateUTC.setLocalTZOffset(parseInt(DOM$.i("TimezoneAdjust").value));
panelUpdate(dateUTC);
}
function focusTZAdjust() {
dateUTC.stop();
}
function changeDaylightSavingTime() {
dateUTC.stop();
dateUTC.setDSTOffset(DOM$.i("DaylightSavingTime").checked ? 60 : 0);
panelUpdate(dateUTC);
}
/***********************************************************************
Change UTC Panel
***********************************************************************/
function changeJulianDate() {
dateUTC.stop();
let value = DOM$.i("JulianDate").value.trim();
let n = value.indexOf(".");
if (n > -1) {
dateUTC.setJulianDate(Number(value));
}
else {
let temp = dateUTC.getJulianDate().toString();
let n = temp.indexOf(".");
if (n > -1) {
dateUTC.setJulianDate(Number(value + temp.substring(n)));
}
else {
dateUTC.setJulianDate(Number(value));
}
}
panelUpdate(dateUTC);
}
function changeModifiedJulianDate() {
dateUTC.stop();
dateUTC.setModifiedJulianDate(DOM$.i("ModifiedJulianDate").value);
panelUpdate(dateUTC);
}
function changeJulianDay() {
dateUTC.stop();
dateUTC.setJulianDay(DOM$.i("JulianDay").value);
panelUpdate(dateUTC);
}
function changeUT() {
dateUTC.stop();
dateUTC.setUT(DOM$.i("UT").value);
panelUpdate(dateUTC);
}
function changeEpoch() {
dateUTC.stop();
dateUTC.setEpoch(DOM$.i("Epoch").value);
panelUpdate(dateUTC);
}
function changeJulianCentury() {
dateUTC.stop();
dateUTC.setJulianCentury(DOM$.i("JulianCentury").value);
panelUpdate(dateUTC);
}
/***********************************************************************
Change TAI Panel
***********************************************************************/
function changeTAIJulianDate() {
dateUTC.stop();
dateTAI.setJulianDate(DOM$.i("TAIJulianDate").value);
setFromTAI();
updateDateTimePanel();
}
function changeTAIModifiedJulianDate() {
dateUTC.stop();
dateTAI.setModifiedJulianDate(DOM$.i("TAIModifiedJulianDate").value);
setFromTAI();
updateDateTimePanel();
}
function changeTAIJulianDay() {
dateUTC.stop();
dateTAI.setJulianDay(DOM$.i("TAIJulianDay").value);
setFromTAI();
updateDateTimePanel();
}
function changeTAIUT() {
dateUTC.stop();
dateTAI.setUT(DOM$.i("TAIUT").value);
setFromTAI();
updateDateTimePanel();
}
function changeTAIEpoch() {
dateUTC.stop();
dateTAI.setEpoch(DOM$.i("TAIEpoch").value);
setFromTAI();
updateDateTimePanel();
}
function changeTAIJulianCentury() {
dateUTC.stop();
dateTAI.setJulianCentury(DOM$.i("TAIJulianCentury").value);
setFromTAI();
updateDateTimePanel();
}
/***********************************************************************
Change TT Panel
***********************************************************************/
function changeTTJulianDate() {
dateUTC.stop();
dateTT.setJulianDate(DOM$.i("TTJulianDate").value);
setFromTT();
updateDateTimePanel();
}
function changeTTModifiedJulianDate() {
dateUTC.stop();
dateTT.setModifiedJulianDate(DOM$.i("TTModifiedJulianDate").value);
setFromTT();
updateDateTimePanel();
}
function changeTTJulianDay() {
dateUTC.stop();
dateTT.setJulianDay(DOM$.i("TTJulianDay").value);
setFromTT();
updateDateTimePanel();
}
function changeTTUT() {
dateUTC.stop();
dateTT.setUT(DOM$.i("TTUT").value);
setFromTT();
updateDateTimePanel();
}
function changeTTEpoch() {
dateUTC.stop();
dateTT.setEpoch(DOM$.i("TTEpoch").value);
setFromTT();
updateDateTimePanel();
}
function changeTTJulianCentury() {
dateUTC.stop();
dateTT.setJulianCentury(DOM$.i("TTJulianCentury").value);
setFromTT();
updateDateTimePanel();
}
/***********************************************************************
Change TCG Panel
***********************************************************************/
function changeTCGJulianDate() {
dateUTC.stop();
dateTCG.setJulianDate(DOM$.i("TCGJulianDate").value);
setFromTCG();
updateDateTimePanel();
}
function changeTCGModifiedJulianDate() {
dateUTC.stop();
dateTCG.setModifiedJulianDate(DOM$.i("TCGModifiedJulianDate").value);
setFromTCG();
updateDateTimePanel();
}
function changeTCGJulianDay() {
dateUTC.stop();
dateTCG.setJulianDay(DOM$.i("TCGJulianDay").value);
setFromTCG();
updateDateTimePanel();
}
function changeTCGUT() {
dateUTC.stop();
dateTCG.setUT(DOM$.i("TCGUT").value);
setFromTCG();
updateDateTimePanel();
}
function changeTCGEpoch() {
dateUTC.stop();
dateTCG.setEpoch(DOM$.i("TCGEpoch").value);
setFromTCG();
updateDateTimePanel();
}
function changeTCGJulianCentury() {
dateUTC.stop();
dateTCG.setJulianCentury(DOM$.i("TCGJulianCentury").value);
setFromTCG();
updateDateTimePanel();
}