Created
December 23, 2021 00:50
-
-
Save pocc/fd7113f13480ddca96bf526e06d7ed24 to your computer and use it in GitHub Desktop.
Show alternative timesystems for the day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uint6ToB64 (nUint6) { | |
// Taken from https://developer.mozilla.org/en-US/docs/Glossary/Base64 | |
return nUint6 < 26 ? | |
nUint6 + 65 | |
: nUint6 < 52 ? | |
nUint6 + 71 | |
: nUint6 < 62 ? | |
nUint6 - 4 | |
: nUint6 === 62 ? | |
43 | |
: nUint6 === 63 ? | |
47 | |
: | |
65; | |
} | |
function hmsInts() { | |
hmsStr = new Date().toISOString().substr(11,8).split(':'); | |
return hmsStr.map((s) => parseInt(s)) | |
}; | |
function UTCTimeInHMS = () => { | |
return new Date().toISOString().substr(11,8); | |
} | |
function UTCTimeInBase64() { | |
result=''; | |
for (t of hmsInts()) { | |
result += String.fromCharCode(uint6ToB64(t)) | |
}; | |
return result; | |
} | |
function UTCTimeInMillidays() { | |
const hms = hmsInts(); | |
const dayFraction = hms[0]/24 + hms[1]/24/60 + hms[2]/24/60/60; | |
return Math.round(1000000*dayFraction); | |
} | |
console.log(UTCTimeInHMS(), UTCTimeInBase64(), UTCTimeInMillidays()) | |
// Example output is 00:45:51 Atz 31840 | |
// 00:45:51 is UTC time 00:45:51 | |
// Atz is A/X t/8 z/8, where X88 are 24 60 60, so the max values for hours/minutes/seconds | |
// 31840 is 31840/1000000, so 31,480 parts of a day's 1,000,00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment