ServerStorage.os.timeConverter:40: attempt to perform arithmetic (div) on function and number -

I’m working on making a os.time converter and when i try to test it, I always get this error:

ServerStorage.os.timeConverter:40: attempt to perform arithmetic (div) on function and number

I’m not sure what I’ve done wrong here.
MODULE:

local osTimeConverter = {
	["statsTable"] = {

	},
	["presetSettings"] = {
		["SecondsInADay"] = 86400,
		["DaysInARegularYear"] = 365,
		["HoursInADay"] = 24
	}
}
--[[
Date Format For Module:
Taken at 12th December, 2020 at 18:13
local Date = {
	["year"] = 2020,
	["month"] = 12,
	["day"] = 12,
	["hour"] = 18,
	["min"] = 13,
	["sec"] = 0
	
	
}
]]


local statsTable = osTimeConverter.statsTable
local presetSettings = osTimeConverter.presetSettings

function osTimeConverter.WorkOutTimeInSecondsBetweenA_B(a, b)
	return os.difftime(a, b)
end

function osTimeConverter.WorkOutTimeFromSpecificDate(Date)
	return os.time(Date)
end
function osTimeConverter.ConvertToDays(Seconds, roundDown)
	local Days 
	if roundDown then
		Days = tostring(math.floor(Seconds/osTimeConverter.presetSettings.SecondsInADay)).." Days Have Gone Past Since the Unix Epoch"
	else
		Days = tostring(Seconds/osTimeConverter.presetSettings.SecondsInADay).." Days Have Gone Past Since the Unix Epoch"
	end
	statsTable.Days = Days

end

function osTimeConverter.ConvertToYears(Seconds)
	local Days = osTimeConverter.ConvertToDays(Seconds)
	local Years = tostring(math.floor(Days/presetSettings.DaysInARegularYear)).." Years Have Gone Past Since The Unix Epoch"
	statsTable.Years = Years

end

function osTimeConverter.ConvertToHours(Seconds)
	local Hours = tostring(math.floor(Seconds/presetSettings.HoursInADay)).." Hours Have Gone Past Since The Unix Epoch"
	statsTable.Hours = Hours
end
function osTimeConverter.ReturnEverything()
	local seconds = os.time
	osTimeConverter.ConvertToDays(seconds, true)
	osTimeConverter.ConvertToHours(seconds)
	osTimeConverter.ConvertToDays(seconds)
	return statsTable
end



return osTimeConverter

SERVER SCRIPT:

local os_timeConverter = require(game.ServerStorage["os.timeConverter"])
while wait(1) do
	local timeTable = os_timeConverter.ReturnEverything()
	for i, v in pairs(timeTable) do
		print(v)
	end
end
````

I made this because I was bored

I think the issue is in your osTimeCoverter.ReturnEverything function where you initialize seconds. It is supposed to be local seconds = os.time() not local seconds = os.time

1 Like