Created
August 6, 2016 01:28
-
-
Save operator-DD3/2351325936b21a87ea866c2007250f72 to your computer and use it in GitHub Desktop.
A simple function to calculate the Mars Sol Date (MSD) and the Coordinated Mars Time (MTC) from the current number of seconds since the UNIX epoch.
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 mars_time() | |
local ms = os.time()*1000 | |
local JDut = 2440587.5 + (ms /86400000) | |
local JDtt = JDut + (35 + 32.184) / 86400 | |
local J2000 = JDtt - 2451545.0 | |
local MSD = ((J2000 - 4.5)/1.027491252) + 44796 - 0.00096 | |
local MTC = (24 * MSD) % 24 | |
local h = math.floor(MTC) | |
local m = math.floor((MTC - h)*60) | |
local s = math.floor((MTC - h - (m/60))*60*60) | |
return string.format("%0.5f", MSD), h .. ":" .. m .. ":" .. s | |
end | |
while true do | |
msd, hms = mars_time() | |
os.execute("clear") | |
print("Mars Sol Date:", msd) | |
print("Coordinated Mars Time:", hms) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is NOT platform independent. This function assumes that os.time() returns the number of elapsed seconds since the UNIX epoch. Some Lua platforms behave differently and this script must be modified in such instances.