From 4aab7c88d07316cedcc62e9d86683ce9f5782a06 Mon Sep 17 00:00:00 2001 From: zlaxy Date: Sun, 12 Apr 2020 01:50:33 +0300 Subject: [PATCH] add converter --- dtime.css | 32 +++++++---- dtime.js | 31 +++++++---- dtimeconv.js | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 4 +- 4 files changed, 193 insertions(+), 21 deletions(-) create mode 100644 dtimeconv.js diff --git a/dtime.css b/dtime.css index 2e1fc48..20f6fab 100644 --- a/dtime.css +++ b/dtime.css @@ -1,21 +1,20 @@ * { - margin:0; - padding:0; + margin: 0; + padding: 0; } html { - width:100%; - height:100%; - position:relative; - background:#f1f1f1; - color:#326f0c; + width: 100%; + height: 100%; + position: relative; + background: #f1f1f1; + color: #326f0c; font-size: 55px; } #wrap { - position:absolute; - text-align:center; position: absolute; + text-align: center; 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; +} diff --git a/dtime.js b/dtime.js index 055315a..a28e80b 100644 --- a/dtime.js +++ b/dtime.js @@ -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; - var dtimestr = h+":"+az(m)+":"+az(s); - return [ddatestr, dtimestr, ddaystr]; + 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() { diff --git a/dtimeconv.js b/dtimeconv.js new file mode 100644 index 0000000..718c13a --- /dev/null +++ b/dtimeconv.js @@ -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 = ` +
Erisian:
+ + + + + + + + + + + + + + +
yoldseasondayhourminutesecond
+
Christian:
+ + + + + + + + + + + + + + +
yearmonthdayhourminutesecond
+

+`; + return convinnerhtml; +} diff --git a/index.html b/index.html index f9a4605..7a9918d 100644 --- a/index.html +++ b/index.html @@ -3,10 +3,12 @@ +

Need javascript enabled

-

00:00:00

+

0:00:00

+