-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTimestampConverter.hta
451 lines (376 loc) · 9.17 KB
/
TimestampConverter.hta
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<html>
<!--
Timestamp Converter
Copyright (c) 2007, 2009 by Ildar Shaimordanov
-->
<head>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="Timestamp Converter"
BORDER="dialog"
BORDERSTYLE="normal"
CAPTION="yes"
CONTEXTMENU="no"
ICON=""
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="yes"
NAVIGABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="normal" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Timestamp Converter</title>
<style type="text/css">
* {
font-family: Verdana, Tahoma, Helvetica, sans-serif;
font-size: 12px;
}
body {
margin: 0;
padding: 0;
}
#body {
background-color: #ccc;
height: 300px;
padding-left: 2px;
padding-right: 2px;
width: 420px;
}
form {
padding: 0;
}
fieldset {
margin: 5px 0;
padding: 5px;
}
fieldset div.label {
float: left;
padding-right: 2px;
text-align: right;
width: 85px;
}
fieldset div.panel {
margin-bottom: 5px;
}
#timestamp-view {
}
#timestamp-view input#T {
width: 300px;
}
#human-friendly-view {
}
#human-friendly-view input.xf_spinbutton_value {
width: 90px;
}
#human-friendly-view select {
width: 102px;
}
#formatted-view {
}
#formatted-view input,
#formatted-view select {
width: 100%;
}
</style>
<style type="text/css">
div.xf_spinbutton_frame {
display: inline;
padding-right: 12px;
position: relative;
}
div.xf_spinbutton_frame input.xf_spinbutton_value {
text-align: right;
}
div.xf_spinbutton_frame input.xf_spinbutton_up,
div.xf_spinbutton_frame input.xf_spinbutton_down {
font-size: 4px;
margin: 0;
padding: 0;
position: absolute;
width: 12px;
}
div.xf_spinbutton_frame input[type="button"] {
right: 0;
}
div.xf_spinbutton_frame input.xf_spinbutton_up {
margin-bottom: 10px;
}
div.xf_spinbutton_frame input.xf_spinbutton_down {
margin-top: 11px !important;
margin-top: 12px;
}
</style>
<script type="text/javascript" src="js/Date.js"></script>
<script type="text/javascript" src="js/String.js"></script>
<script type="text/javascript" src="js/web/XHTMLDOM.utils.SpinButton.js"></script>
<script type="text/javascript">
(function()
{
/**
* Common behavior callback for all spinbuttons
*/
var behavior = function(el, options)
{
// Prevent duplicated changes of fields
if ( behavior.again ) {
behavior.again = false;
return;
}
behavior.again = true;
switch ( el.id ) {
case 'T':
var here = new Date(behavior.T.getValue() * 1000);
if ( ! here ) {
return;
}
behavior.Y.updateValue(here.getFullYear());
behavior.M.selectedIndex = here.getMonth();
behavior.D.updateValue(here.getDate());
behavior.hh.updateValue(here.getHours());
behavior.mm.updateValue(here.getMinutes());
behavior.ss.updateValue(here.getSeconds());
break;
case 'Y':
case 'M':
behavior.updateTimestamp(true);
break;
case 'D':
case 'hh':
case 'mm':
case 'ss':
behavior.updateTimestamp();
break;
}
};
/**
* Updater for the formatted time view
*/
behavior.updateFormat = function()
{
var here = new Date(behavior.T.getValue() * 1000);
var bfo = behavior.formatter.options;
/*
var format = bfo[bfo.selectedIndex].text
.replace('YYYY', here.getFullYear())
.replace('MMM', here.getMonthShortName())
.replace('MM', (here.getMonth() + 1).dec(2, '0'))
.replace('DD', here.getDate().dec(2, '0'))
.replace('hh', here.getHours().dec(2, '0'))
.replace('h', here.getHours() <= 12 ? here.getHours() : here.getHours() - 12)
.replace('mm', here.getMinutes().dec(2, '0'))
.replace('ss', here.getSeconds().dec(2, '0'))
.replace('TZ', here.getTZ())
.replace('DT', here.getDaytime());
behavior.formatted.value = format;
*/
behavior.formatted.value = Date.format(bfo[bfo.selectedIndex].value, here);
behavior.formatter.blur();
};
/**
* Updater for the timestamp view
*/
behavior.updateTimestamp = function(fixLastDayOfMonth)
{
var here = new Date(
behavior.Y.getValue(),
behavior.M.selectedIndex,
behavior.D.getValue(),
behavior.hh.getValue(),
behavior.mm.getValue(),
behavior.ss.getValue(),
0);
if ( fixLastDayOfMonth ) {
behavior.D.updateOptions({
max: here.getDaysInMonth()
});
}
behavior.T.updateValue(parseInt(here.getTime() / 1000));
behavior.updateFormat();
};
/**
* Initialize of the formatted time view
*/
function initFormat()
{
behavior.formatter = document.getElementById('formatter');
behavior.formatted = document.getElementById('formatted');
if ( document.attachEvent ) {
behavior.formatter.attachEvent('onchange', behavior.updateFormat);
} else {
behavior.formatter.addEventListener('change', behavior.updateFormat, true);
}
};
/**
* Initialize of all spinbuttons
*/
function initSpinbuttons()
{
var now = new Date();
if ( ! initSpinbuttons.initialized ) {
// Prevent the double initialization of the view
initSpinbuttons.initialized = true;
// Timestamp
behavior.T = new XHTMLDOM.utils.Spinbutton(document.getElementById('T'), {
rotate: 1,
behavior: behavior
});
// Year
behavior.Y = new XHTMLDOM.utils.Spinbutton(document.getElementById('Y'), {
value: now.getFullYear(),
rotate: 1,
behavior: behavior
});
// Month
behavior.M = document.getElementById('M');
behavior.M.onchange = function()
{
behavior(behavior.M);
};
// Date
behavior.D = new XHTMLDOM.utils.Spinbutton(document.getElementById('D'), {
value: now.getDate(),
min: 1,
max: now.getDaysInMonth(),
rotate: 1,
behavior: behavior
});
// Hours
behavior.hh = new XHTMLDOM.utils.Spinbutton(document.getElementById('hh'), {
value: now.getHours(),
min: 0,
max: 23,
rotate: 1,
behavior: behavior
});
// Minutes
behavior.mm = new XHTMLDOM.utils.Spinbutton(document.getElementById('mm'), {
value: now.getMinutes(),
min: 0,
max: 59,
rotate: 1,
behavior: behavior
});
// Seconds
behavior.ss = new XHTMLDOM.utils.Spinbutton(document.getElementById('ss'), {
value: now.getSeconds(),
min: 0,
max: 59,
rotate: 1,
behavior: behavior
});
}
behavior.T.updateValue(parseInt(now.getTime() / 1000));
};
/**
* Initialize the frame of application. Create the window and show it
*/
function initWin()
{
initFormat();
initSpinbuttons();
};
/**
* Initialize the standalone HTA
*/
function initHta()
{
// set the window size
var w = 420, h = 300;
window.moveTo((window.screen.width - w) / 2, (window.screen.height - h) / 2);
window.resizeTo(w, h);
// initialize the timestamp converter
initWin();
};
/**
* Handles keystrokes (for HTA only)
*/
function handleKeydown(e)
{
var e = e || event;
// F5
if ( e.keyCode == 116 ) {
initWin();
return false;
}
// Esc
if ( e.keyCode == 27 ) {
window.close();
return false;
}
};
if ( window.attachEvent ) {
if ( window.oHTA && oHTA.applicationName ) {
window.attachEvent('onload', initHta);
document.attachEvent('onkeydown', handleKeydown);
} else {
window.attachEvent('onload', initWin);
}
} else {
window.addEventListener('load', initWin, true);
}
})();
</script>
</head>
<body>
<div id="body">
<form action="" onsubmit="return false">
<h1 style="font-size: 1.2em; margin: 0;">Timestamp Converter</h1>
<div style="font-size: 9px;">Copyright © 2007, 2009 by Ildar Shaimordanov</div>
<fieldset id="timestamp-view">
<legend>Timestamp view</legend>
<div class="label">Timestamp: </div>
<input type="text" id="T" />
</fieldset>
<fieldset id="human-friendly-view">
<legend>Human-friendly view</legend>
<div class="panel">
<div class="label">Date: </div>
<input type="text" id="Y" />
<select id="M">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<input type="text" id="D" />
</div>
<div class="panel">
<div class="label">Time: </div>
<input type="text" id="hh" />
<input type="text" id="mm" />
<input type="text" id="ss" />
</div>
</fieldset>
<fieldset id="formatted-view">
<legend>Formatted view</legend>
<select id="formatter">
<option value="%b %d, %Y %H:%M:%S %z">MMM DD, YYYY hh:mm:ss TZ</option>
<option value="%Y/%m/%d %H:%M:%S">YYYY/MM/DD hh:mm:ss</option>
<option value="%d.%m.%Y %H:%M:%S">DD.MM.YYYY hh:mm:ss</option>
<option value="%d-%m-%Y %H:%M:%S">DD-MM-YYYY hh:mm:ss</option>
<option value="%d-%m-%Y">DD-MM-YYYY</option>
<option value="%d.%m.%Y">DD.MM.YYYY</option>
<option value="%d %b %Y">DD MMM YYYY</option>
<option value="%b %d %Y">MMM DD YYYY</option>
<option value="%H:%M:%S">hh:mm:ss</option>
<option value="%I:%M:%S %p">h:mm:ss DT</option>
</select>
<input type="text" id="formatted" readonly="readonly" />
</fieldset>
</form>
</div>
</body>
</html>