Help with os.date()

I am currently rewriting my admin system and working on displaying the date that the user is going to get unbanned with this.

os.date("%c", seconds)

I have all my math right, but it is always ahead and I noticed exactly the same amount, and later found that is was GMT time. From my understanding client returns their time zone.

Here is the issue! This is an admin system I can’t rely on the client to give me the time for their time zone, otherwise exploiters could send false values. How can I do this?

Instead of relying on time zones using os.date, I would recommend doing the math yourself and displaying that.

local years = math.floor(seconds / 60 / 60 / 24 / 365)
seconds -= years * 60 * 60 *24 * 365
local days = math.floor(seconds / 60 / 60/ 24)
seconds -= days * 60 * 60 * 24
local hours = math.floor(seconds / 60 / 60)
seconds -= hours * 60 * 60
local minutes = math.floor(seconds / 60)
seconds -= minutes * 60
--then seconds would be the seconds left.

Or, you could always show it in UTC (Coordinated Universal Time) and state that it is in UTC, then again, you could also do this for any time zone you wanted to and tell them to translate it themself.

I would preferably like to present the date to the users so younger audiences can still understand, I had an idea but not sure how safe it would be.

What if I sent a remote when the user joined that returns the os.time() from the client, I then take one from the server and subtract the two for the difference. I am aware it won’t be completely accurate but it is just for visuals. Then whatever the difference is I subtract my time before I format with os.date()

I changed it in my original post.

There is honestly no way you could rely on the client for valid information on time zone. But, if you really wanted to, have them choose a time zone from a list of time zones and present it for that time zone.

If you think about it, this is just a visual thing so if an exploiter wants to mess with their own visuals, go for it, if it is a exploiter they will most likely never touch that account again since it will be an alt. In the end they would still be banned

Then why not have them input their current time? You can go from there.

Seems shady + this will be used in all my projects and I don’t really think that is needed when I can calculate it.

I wouldn’t mind it displaying “You will be unbanned in X days X hours X minutes” but I dislike that because I will have to do lots of if statements to make sure it only shows what is needed, example: Banned for 1 hour it may show “0 days, 1 hour, 0 minutes, 0 seconds”, I don’t need any of those 0s

You wouldn’t really need too many if statements, as you can condense it through the string and/or method ex:

local years = math.floor(seconds / 60 / 60 / 24 / 365)
seconds -= years * 60 * 60 *24 * 365
local days = math.floor(seconds / 60 / 60/ 24)
seconds -= days * 60 * 60 * 24
local hours = math.floor(seconds / 60 / 60)
seconds -= hours * 60 * 60
local minutes = math.floor(seconds / 60)
seconds -= minutes * 60

local times = {
	years = years, 
	days = days, 
	hours = hours, 
	minutes = minutes, 
	seconds = seconds,
}

local nt = {}

for i,v in pairs(times) do
	if v > 0 then
		nt[i] = v
	end
end

print((nt.years and nt.years..(nt.years > 1 and " years " or " year ") or "")
	..(nt.days and nt.days..(nt.days > 1 and " days " or " day ") or "")
	..(nt.hours and nt.hours..(nt.hours > 1 and " hours " or " hour ") or "")
	..(nt.minutes and nt.minutes..(nt.minutes > 1 and " minutes " or " minute ") or "")
	..(nt.seconds and nt.seconds..(nt.seconds > 1 and " seconds " or " second ") or "")
)