Activity Logger

I am creating a resort game where I want to log the amount of time a staff member plays a game per week.

So, that means I want to log the amount of time they play every time they join the game, and add it to their weekly total. But, I don’t know how to reset this weekly total after a week ends, is there a way to do this? I have tried thinking up a way using os.date or time, I just don’t understand how. Anyone have any ideas?

3 Likes

Maybe something like this could work:

  1. When a staff member joins, log the os.time as the “start” time.
  2. When they leave, log the os.time as the “end” time, and log it somewhere (preferably off-site like Google sheets, Trello or some other service).
1 Like

Google Sheets and Trello are not databases, do not use them as such.

I’d suggest having a dictionary which stores join times of staff. When they leave, get the timediff and increment an OrderedDataStore.

1 Like

Just so you don’t have to look it up: there are 604,800 seconds in a week. os.time gives you the number of seconds that have passed since January 1st, 1970.

I meant to reply to the OP, sorry. @jvstaldjni

Since everyone is replying with using os.time then I decided to uh yes :

System.Times = {
	Day = 86400, -- Day in seconds
	Week = 86400 * 7, -- Week in Seconds
	Month = 86400 * 30, -- Month in seconds
	Year = 86400 * 30 * 12, -- Year in seconds
}

This is not necessarily correct. Months can have fewer or more than 30 days.

1 Like

You can record the exact date and time of the activity by passing the result of os.time() into os.date(). It returns a table providing values for month, day, day of week, etc.

-- *t for local time, !*t for UTC
-- second argument can be a unix timestamp, but defaults to the current time if left nil

local date = os.date("!*t")
for i,v in pairs(date) do
	print(i..": "..tostring(v))
end
1 Like