Simple question, I’m attempting to calculate seconds, but it converts to minutes instead for whatever reason, even if the number is 2.
local Years = Floor(Time / TimeManager.Settings.years.Time)
local Days = Floor(Fmod(Time, TimeManager.Settings.days.Time) / TimeManager.Settings.hours.Time)
local Hours = Floor(Fmod(Time, TimeManager.Settings.hours.Time) / TimeManager.Settings.minutes.Time)
local Minutes = Floor(Fmod(Time, TimeManager.Settings.minutes.Time) / TimeManager.Settings.seconds.Time)
local Seconds = Floor(Fmod(Time, TimeManager.Settings.seconds.Time))
Floor is math.floor and Fmod is math.fmod
TimeManager.Settings = {
years = {
Aliases = {'year', 'yrs', 'yr', 'y'},
Time = 31536000
},
days = {
Aliases = {'day', 'd'},
Time = 86400
},
hours = {
Aliases = {'hour', 'hrs', 'hr'},
Time = 3600
},
minutes = {
Aliases = {'minute', 'mins', 'min', 'm'},
Time = 60
},
seconds = {
Aliases = {'second', 'secs', 'sec', 's'},
Time = 1
}
}
If you want to get the amount of seconds that have passed of the current minute, I think you should use the amount of seconds in a minute in your fmod, like this:
local Seconds = Floor(Fmod(Time, TimeManager.Settings.**minutes**.Time))
But I am not entirely sure what you mean by “it converts to minutes instead for whatever reason, even if the number is 2”…
local Time = --whatever it is (in seconds)
local RunningTime = Time
local Years = math.floor(time/TimeManager.Settings.years.Time)
RunningTime = RunningTime % TimeManager.Settings.years
local Days = math.floor(time/TimeManager.Settings.days.Time)
RunningTime = RunningTime % TimeManager.Settings.years
local Hours = math.floor(time/TimeManager.Settings.hours.Time)
RunningTime = RunningTime % TimeManager.Settings.years
local Minutes = math.floor(time/TimeManager.Settings.minutes.Time)
RunningTime = RunningTime % TimeManager.Settings.years
local Seconds = RunningTime
Without an explanation, I wouldn’t even understand your way of doing it, how it should be calculated:
OsTime + (Floor(Length) * Multiplier) - OsTime
I’d like to hear if you want to explain your code though.
Anyways, the issue has been fixed, after some investigation, I realized I multiplied seconds by 60 instead of 1. In other words, every time table now has a Multiplier value and a Divider value.
for Index, Value in pairs(TimeManager.Settings) do
local TypeLower = Type:lower()
if (TypeLower == Index or table.find(Value.Aliases, TypeLower)) then
Time = OsTime + (Floor(Length) * Value.Multiplier) - OsTime
Passed = true
break
end
end
May be a bit complex to see in person, but very efficient when it comes to execution.
My code basically had a running total (RunningTime) that I could freely modify.
Then, I rounded down the number of years, based on what you had in your settings thingy.
After that, I used a modulus operator (%) on the running total. The modulus operator basically returns the remainder when RunningTotal is divided by the seconds in a year.