Os.date returning nil

Hi. I’m using os.date for my ban screen, and noticed that with permanent bans (which is the current timestamp + 31557600000), os.date point blank returns nil.

I know it’s not an implementation issue, as it works with temporary bans and lower numbers.
Could this be an invisible limit on os.date, could I have hit the buffer??

I assume this has to do with the “year 2038” problem. this is because the latest time that can be represented in Unix’s signed 32-bit integer time format is 03:14:07 on Tuesday, 19 January 2038. Instead of using a time for a permban use a boolean which makes stuff way easier as it doesn’t require calculations and all.

I’ve read about this before and it can cause issues in the future or with possibly stuff such as this, I’m sure there eventually come a fix when the time comes but that’s something for the future.

Sources:
Wikipedia
HowStuffWorks

While a boolean may be the easiest of seeing who is permanently banned or not, an alternative is providing os.date with the format and current timestamp which can be used to create a table of date values. You can use this and check the current date when a player joins, and if there is currently a ban on record in which after a certain date they’ll be unbanned, meaning you’ll be able to create various timed bans such as an hour, a day, month, year etc.

local DateTable = os.date("!*t", os.time())

local CurrentDate = DateTable.day.."/"..DateTable.month.."/"..DateTable.year

To create what you could call a ‘permanent’ ban with this system just add a hundred or so years to the timestamp that you wish to unban them by.

Since it’s only a ban screen, I don’t see anything wrong with doing:

string.format(
    "Banned until: %s",
    os.date("%c", t) or "permanent"
)

I just checked and the issue here is that the resulting date value you’ve created is past the year 3000 (see here for calculation: Rink ). On Windows at least, dates past 3000 will return an error, so we return nil in this case.

I agree with @ee0w’s suggestion, but it’s worth noting that not all platforms will necessarily return nil, so don’t rely on it returning nil.

Year 2038 problem doesn’t really apply here, as we don’t use 32-bit timestamps. The year 3000 problem though, we will have to solve some time in the next 900 years…