First, let’s see how we normally would display time in a 24 hour clock using math:
local function toHMS(s)
return string.format("%02i:%02i:%02i", s/60^2, s/60%60, s%60)
end
-
s/60^2
, how many times an hour (3600 seconds) has been past s
seconds.
-
s/60
, how many times a minute (60 seconds) has been past s
seconds (1 hour = 3600 seconds). s/60%60
, how many minutes remain after every hour (60 minutes).
-
s%60
, how many seconds remain after every minute (60 seconds).
Now, about creating in-experience days:
Create a new unit, in here I’ll be calling “inexday”, kinda like the Sol.
You can use math to figure this out. I can think of a few ways you could do this:
- A day can contain multiple inexdays (most useful) or an inexday lasts multiple days (more confusing). For simplicity we keep the same day, month, year, etc as earth.
- A day is actually an inexday and the way we count time on Earth is scaled accordingly (1 sec is actually 1 inexsec, and so on), since the unix epoch.
- Like 1, but you create a totally new calendar based on the earth second. (Good luck)
Case 1
Let’s define our unit, for example
local INEXDAYS_PER_DAY=2 --You can call this "scale" instead, since its not just for days
Let’s display our local time in earth using DateTime:
local function getTime()
local timeTable = DateTime.now():ToLocalTime()
return timeTable
end
local function format(timeTable)
local dateTime = DateTime.fromLocalTime(timeTable.Year, timeTable.Month, timeTable.Day, timeTable.Hour, timeTable.Minute, timeTable.Second, timeTable.Millisecond)
return dateTime:FormatLocalTime("LLL", "en-us")
end
print(format(getTime()))
Now we can calculate inextime and keep earth days and inexdays:
local function getTime()
local now = DateTime.now()
local timeTable = now:ToLocalTime()
local inexTimeTable = DateTime.fromUnixTimestamp((now.UnixTimestamp % (24*60*60))*INEXDAYS_PER_DAY):ToLocalTime()
timeTable.Inexday = inexTimeTable.Day
timeTable.Inexhour = inexTimeTable.Hour
timeTable.Inexminute = inexTimeTable.Minute
timeTable.Inexsecond = inexTimeTable.Second
timeTable.Inexmillisecond = inexTimeTable.Millisecond
return timeTable
end
local function formatInex(timeTable)
local dateTime = DateTime.fromLocalTime(
timeTable.Year,
timeTable.Month,
timeTable.Day,
timeTable.Inexhour,
timeTable.Inexminute,
timeTable.Inexsecond,
timeTable.Inexmillisecond
)
return dateTime:FormatLocalTime("LL", "en-us")
.. (" Inexday: %02d "):format(timeTable.Inexday)
.. dateTime:FormatLocalTime("LT", "en-us")
end
print(formatInex(getTime()))
Case 2
We just multiply the unix timestamp and assume the inex time started since the unix epoch
local function format(datetime)
return DateTime.fromUnixTimestamp(datetime.UnixTimestamp*INEXDAYS_PER_DAY):FormatLocalTime("LLL", "en-us")
end
print(format(DateTime.now()))