Skip to content

Instantly share code, notes, and snippets.

@operator-DD3
Created August 6, 2016 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save operator-DD3/2351325936b21a87ea866c2007250f72 to your computer and use it in GitHub Desktop.
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.
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
@operator-DD3
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment