Os.date - Useful but not here?

From a previous post on a thread, I would like to have the os.date function enabled. This function can prove extremely usefu, as it removes the need for us to do complicated operations on the return value of ‘tick()’ or ‘os.time()’
Basically, os.date can do this:

local date = os.date('*t')
for _, v in pairs(date) do
print(_, v)
end

and the output would look something like:

hour    22
min     52
wday    1
day     13
month   4
year    2014
sec     47
yday    103
isdst   true

As you can tell, this would be an easier way to create ‘calendars’ or season-based games in ROBLOX.
Plus, it would greatly help with the creation of time-of-day scripts, as you would only have to do something like this:
(please excuse the fact that I didn’t use :SetMinutesAfterMidnight, I was too lazy to convert all three values to minutes)

while true do
	local date = os.date('*t')
	game.Lighting.TimeOfDay = date.hour..":"..date.min..":"..date.sec
	wait(1)
end

As you can see, this is a lot less complicated than some current time-of-day scripts which replicate the current time-of-day.

Plus, it provides an easy way for us to tell whether the current time of day is in daylight savings time which could be useful in some cases (I can’t really think of any as of right now, but I’m sure with the creativity of ROBLOX users something will happen using it)

5 Likes

Yes this would be very useful and could lead to features like bonus points on weekends, ect.

I tried to do this the other day but I’m rubbish at math. Would be nice if we had os.date :stuck_out_tongue:

I honestly think that being able to set up events in advance without having to shut down every server with an update would be nice. Like, you could set up certain features to be released at certain dates in the feature. Not sure how to express support for something here, so I just hit thank you.

Sure. That would be great :slight_smile:

But with some math you can make your own os.date.

pl0x

If anyone does need date and time and all in UTC, and haven’t gotten to figure out the math, this module will do the trick for you.

1 Like

[quote] If anyone does need date and time and all in UTC, and haven’t gotten to figure out the math, this module will do the trick for you.

http://www.roblox.com/UNIX-Time-to-Date-Module-item?id=181147970 [/quote]

It’s not that we can’t do it (although I’m sure those who haven’t gotten around to making their own module will appreciate that), but that we shouldn’t have to go to such great lengths to get the date/time. I’m going to have to include a date/time module in one of my public models because os.date() is locked – that’s kind of silly.

[quote] If anyone does need date and time and all in UTC, and haven’t gotten to figure out the math, this module will do the trick for you.

http://www.roblox.com/UNIX-Time-to-Date-Module-item?id=181147970 [/quote]

It’s not that we can’t do it (although I’m sure those who haven’t gotten around to making their own module will appreciate that), but that we shouldn’t have to go to such great lengths to get the date/time. I’m going to have to include a date/time module in one of my public models because os.date() is locked – that’s kind of silly.[/quote]

Right. I’m on board with you. Just for the people that would apreciate it, like you said, I thought I’d share.

I have a GetDate function that might be helpful too. I put it together pretty quickly, and should have made it more of an API or library, but a function it is. Gives simple date formatting.

http://www.roblox.com/GetDate-item?id=182602810

I use this code for it, with alterations to the return value if needed.

function time(s)
	local s=type(s)=='number' and s or tick()
	local fy,dim=math.floor(s/126230400),{31,0,31,30,31,30,31,31,30,31,30,31}
	local y,s,m,d,h,mm=fy*4,s-(126230400*fy)
	for i=1,4 do local sy=i==2 and 31622400 or 31536000
		if s<(sy) then break
		else y=y+1 s=s-(sy)
	end end
	for i=1,12 do local sm=(i==2 and ((y%4)==0 and 29 or 28) or dim[i])*86400
		if s<(sm) then m=i break
		else s=s-(sm)
	end end
	local d=math.floor(s/86400) s=s-(d*86400)
	local h=math.floor(s/3600) s=s-(h*3600)
	local mm=math.floor(s/60) s=s-(mm*60)
	return {
		Year=1970+y,
		Month=m,
		Day=d+1,
		Hour=h,
		Minute=mm,
		Second=s,
	}
end

This would’ve been handy on new years, had some fireworks activate at midnight EST; the math was a bit annoying for it

Would this be GMT (+0) timezone?

I believe so, yes.

Anything else wouldn’t make a lot of sense. A neutral GMT is the easiest to offset to other time zones and it’s the most correct most of the times!

Support.

Nine months and 36 Thank Yous later… No Admin has anything to say about this? We must keep trying.

In case anyone finds this thread in the search, os.date has now been added to ROBLOX:
http://devforum.roblox.com/t/insight-on-os-date/46626/4

4 Likes