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)
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.
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.
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.
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