- return false, "Missing time."
- end
- local newtime = tonumber(param)
- if newtime == nil then
- return false, "Invalid time."
- end
- core.set_timeofday((newtime % 24000) / 24000)
- core.log("action", name .. " sets time " .. newtime)
+ local current_time = math.floor(core.get_timeofday() * 1440)
+ local minutes = current_time % 60
+ local hour = (current_time - minutes) / 60
+ return true, ("Current time is %d:%02d"):format(hour, minutes)
+ end
+ local player_privs = core.get_player_privs(name)
+ if not player_privs.settime then
+ return false, "You don't have permission to run this command " ..
+ "(missing privilege: settime)."
+ end
+ local hour, minute = param:match("^(%d+):(%d+)$")
+ if not hour then
+ local new_time = tonumber(param)
+ if not new_time then
+ return false, "Invalid time."
+ end
+ -- Backward compatibility.
+ core.set_timeofday((new_time % 24000) / 24000)
+ core.log("action", name .. " sets time to " .. new_time)
+ return true, "Time of day changed."
+ end
+ hour = tonumber(hour)
+ minute = tonumber(minute)
+ if hour < 0 or hour > 23 then
+ return false, "Invalid hour (must be between 0 and 23 inclusive)."
+ elseif minute < 0 or minute > 59 then
+ return false, "Invalid minute (must be between 0 and 59 inclusive)."
+ end
+ core.set_timeofday((hour * 60 + minute) / 1440)
+ core.log("action", ("%s sets time to %d:%02d"):format(name, hour, minute))