add converter

This commit is contained in:
ivan 2020-04-12 01:50:33 +03:00
parent 7d95148cd3
commit 4aab7c88d0
4 changed files with 193 additions and 21 deletions

View File

@ -15,7 +15,6 @@ html {
#wrap {
position: absolute;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
@ -33,3 +32,18 @@ html {
#dtime {
font-size: 303%;
}
.hidden {
display: none;
}
.secsize {
font-size: 73px;
color: gray;
vertical-align: super;
}
table {
font-size: 22px;
margin: auto;
}

View File

@ -43,7 +43,7 @@ function dy(D, M, Y) {
return d;
}
function dtime(gregorianDate) {
function dtime(gregorianDate,resultar="default") {
// Easter Island Winter Time Zone offset (-5*60*60*1000)
var date = new Date(gregorianDate.getTime()-18000000);
@ -65,9 +65,8 @@ function dtime(gregorianDate) {
M--;
D = 73;
}
var ddaystr = dday(D,M,d,sttiby);
var seasonnum = M+1;
switch (M) {
case 0:
M = "Chaos";
@ -93,21 +92,29 @@ function dtime(gregorianDate) {
} else {
var ddatestr = M+" "+az(D)+", "+Y+" YOLD";
}
var h = date.getUTCHours();
var m = date.getUTCMinutes();
var s = date.getUTCSeconds();
var ms = date.getUTCMilliseconds();
var e = h*3600000+m*60000+s*1000+ms;
var ds = Math.round(e/864);
h = Math.floor(ds/10000);
ds%= 10000;
m = Math.floor(ds/100);
ds%= 100;
s = ds;
switch (resultar) {
case "shortsec":
return [ddatestr, h+":"+az(m), ":"+az(s), ddaystr];
break;
case "ddatetime":
return [Y, seasonnum, D, h, m, s];
break;
default:
var dtimestr = h+":"+az(m)+":"+az(s);
return [ddatestr, dtimestr, ddaystr];
break;
}
}
function dday(day, season, yearday, sttiby) {
@ -177,14 +184,16 @@ function dday(day, season, yearday, sttiby) {
function go() {
var iddate = document.getElementById("ddate");
var idtime = document.getElementById("dtime");
var idtimeshort = document.getElementById("dtimeshort");
var idtimesec = document.getElementById("dtimesec");
var idday = document.getElementById("dday");
// Current date-time with any time zone offset
var ddatetime = new Date();
ddatetime = dtime(ddatetime);
ddatetime = dtime(ddatetime, "shortsec");
iddate.innerHTML = ddatetime[0];
idtime.innerHTML = ddatetime[1];
idday.innerHTML = ddatetime[2];
idtimeshort.innerHTML = ddatetime[1];
idtimesec.innerHTML = ddatetime[2];
idday.innerHTML = ddatetime[3];
}
window.onload = function() {

147
dtimeconv.js Normal file
View File

@ -0,0 +1,147 @@
/*
* https://gitlab.com/zlax/dtime-js discrodian date and time converter
*/
function timeclick () {
if (window.dtimescreen) window.dtimescreen++;
else window.dtimescreen = 1;
switch (window.dtimescreen) {
case 1:
document.getElementById("dconv").innerHTML = converterhtml();
var currentdate = new Date();
document.getElementById("ctimeoffset").value = currentdate.getTimezoneOffset();
filltimes(currentdate);
break;
case 2:
document.getElementById("dconv").innerHTML = "";
document.getElementById("dtimesec").classList.toggle('secsize');
break;
case 3:
document.getElementById("dtimesec").classList.toggle('secsize');
document.getElementById("dtimesec").classList.toggle('hidden');
break;
case 4:
document.getElementById("dtimesec").classList.toggle('hidden');
window.dtimescreen = 0;
break;
}
}
function filltimes(convdate) {
var dtimenum = dtime(convdate, "ddatetime");
document.getElementById("dtimeyold").value = dtimenum[0];
document.getElementById("dtimeseason").value = dtimenum[1];
document.getElementById("dtimeday").value = dtimenum[2];
document.getElementById("dtimehour").value = dtimenum[3];
document.getElementById("dtimeminute").value = dtimenum[4];
document.getElementById("dtimesecond").value = dtimenum[5];
var editeddate = new Date (convdate.getTime() - (document.getElementById("ctimeoffset").value * 60000));
document.getElementById("ctimeyear").value = editeddate.getUTCFullYear();
document.getElementById("ctimemonth").value = editeddate.getUTCMonth() + 1;
document.getElementById("ctimeday").value = editeddate.getUTCDate();
document.getElementById("ctimehour").value = editeddate.getUTCHours();
document.getElementById("ctimeminute").value = editeddate.getUTCMinutes();
document.getElementById("ctimesecond").value = editeddate.getUTCSeconds();
}
function converttimes(fromto) {
switch (fromto) {
case "eris":
var dtimeseason = document.getElementById("dtimeseason").value - 1;
var dtimeday = document.getElementById("dtimeday").value - 1;
var ctimeyear = document.getElementById("dtimeyold").value - 1166;
var timestamp = Date.UTC(ctimeyear, 0, 1, 0, 0, 0) +
(dtimeseason * 6307200000) +
(dtimeday * 86400000) +
(document.getElementById("dtimehour").value * 8640000) +
(document.getElementById("dtimeminute").value * 86400) +
(document.getElementById("dtimesecond").value * 864) + 18000000;
if (ly(ctimeyear)) {
if ((dtimeseason == 0) && (dtimeday > 58) || (dtimeseason > 0)) {
timestamp += 86400000;
}
}
filltimes(new Date(timestamp));
break;
case "chri":
var ctime = new Date(Date.UTC(document.getElementById("ctimeyear").value,
document.getElementById("ctimemonth").value - 1,
document.getElementById("ctimeday").value,
document.getElementById("ctimehour").value,
document.getElementById("ctimeminute").value,
document.getElementById("ctimesecond").value) + document.getElementById("ctimeoffset").value * 60000);
filltimes(ctime);
break;
}
}
function converterhtml() {
var convinnerhtml = `
<div>Erisian:</div>
<table><tr>
<td>yold</td>
<td>season</td>
<td>day</td>
<td>hour</td>
<td>minute</td>
<td>second</td>
</tr><tr>
<td><input id="dtimeyold" type="number" min=2000 max=5000 onchange="converttimes('eris')"></td>
<td><input id="dtimeseason" type="number" min=1 max=5 onchange="converttimes('eris')"></td>
<td><input id="dtimeday" type="number" min=1 max=73 onchange="converttimes('eris')"></td>
<td><input id="dtimehour" type="number" min=0 max=9 onchange="converttimes('eris')"></td>
<td><input id="dtimeminute" type="number" min=0 max=99 onchange="converttimes('eris')"></td>
<td><input id="dtimesecond" type="number" min=0 max=99 onchange="converttimes('eris')"></td>
</tr></table>
<div>Christian:</div>
<table><tr>
<td>year</td>
<td>month</td>
<td>day</td>
<td>hour</td>
<td>minute</td>
<td>second</td>
</tr><tr>
<td><input id="ctimeyear" type="number" min=834 max=3834 onchange="converttimes('chri')"></td>
<td><input id="ctimemonth" type="number" min=1 max=12 onchange="converttimes('chri')"></td>
<td><input id="ctimeday" type="number" min=1 max=31 onchange="converttimes('chri')"></td>
<td><input id="ctimehour" type="number" min=0 max=23 onchange="converttimes('chri')"></td>
<td><input id="ctimeminute" type="number" min=0 max=59 onchange="converttimes('chri')"></td>
<td><input id="ctimesecond" type="number" min=0 max=59 onchange="converttimes('chri')"></td>
</tr></table>
<p><select id="ctimeoffset" onchange="converttimes('chri')">
<option value="720">(UTC-12:00) Eniwetok, Kwajalein</option>
<option value="660">(UTC-11:00) Midway Island, Samoa</option>
<option value="600">(UTC-10:00) Hawaii</option>
<option value="540">(UTC-9:00) Alaska</option>
<option value="480">(UTC-8:00) Pacific Time (US &amp; Canada)</option>
<option value="420">(UTC-7:00) Mountain Time (US &amp; Canada)</option>
<option value="360">(UTC-6:00) Central Time (US &amp; Canada), Mexico City</option>
<option value="300">(UTC-5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
<option value="240">(UTC-4:00) Atlantic Time (Canada), Caracas, La Paz</option>
<option value="210">(UTC-3:30) Newfoundland</option>
<option value="180">(UTC-3:00) Brazil, Buenos Aires, Georgetown</option>
<option value="120">(UTC-2:00) Mid-Atlantic</option>
<option value="60">(UTC-1:00 hour) Azores, Cape Verde Islands</option>
<option value="0">(UTC) Western Europe Time, London, Lisbon, Casablanca</option>
<option value="-60">(UTC+1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
<option value="-120">(UTC+2:00) Kaliningrad, South Africa</option>
<option value="-180">(UTC+3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
<option value="-210">(UTC+3:30) Tehran</option>
<option value="-240">(UTC+4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
<option value="-270">(UTC+4:30) Kabul</option>
<option value="-300">(UTC+5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
<option value="-330">(UTC+5:30) Bombay, Calcutta, Madras, New Delhi</option>
<option value="-345">(UTC+5:45) Kathmandu</option>
<option value="-360">(UTC+6:00) Almaty, Dhaka, Colombo</option>
<option value="-420">(UTC+7:00) Bangkok, Hanoi, Jakarta</option>
<option value="-480">(UTC+8:00) Beijing, Perth, Singapore, Hong Kong</option>
<option value="-540">(UTC+9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
<option value="-570">(UTC+9:30) Adelaide, Darwin</option>
<option value="-600">(UTC+10:00) Eastern Australia, Guam, Vladivostok</option>
<option value="-660">(UTC+11:00) Magadan, Solomon Islands, New Caledonia</option>
<option value="-720">(UTC+12:00) Auckland, Wellington, Fiji, Kamchatka</option>
</select></p>
`;
return convinnerhtml;
}

View File

@ -3,10 +3,12 @@
<!-- https://gitlab.com/zlax/dtime-js discrodian date and time -->
<link rel="stylesheet" type="text/css" href="dtime.css">
<script type="text/javascript" src="dtime.js"></script>
<script type="text/javascript" src="dtimeconv.js"></script>
</head>
<div id="wrap">
<p id="ddate">Need javascript enabled</p>
<p id="dday"></p>
<p id="dtime">00:00:00</p>
<p id="dtime" onclick="timeclick()"><b id="dtimeshort">0:00</b><b id="dtimesec">:00</b></p>
<p id="dconv"></p>
</div>
</html>