summaryrefslogtreecommitdiff
path: root/lualibs-os.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualibs-os.lua')
-rw-r--r--lualibs-os.lua24
1 files changed, 18 insertions, 6 deletions
diff --git a/lualibs-os.lua b/lualibs-os.lua
index a4c0ac8..3838b55 100644
--- a/lualibs-os.lua
+++ b/lualibs-os.lua
@@ -382,31 +382,43 @@ end
local timeformat = format("%%s%s",os.timezone(true))
local dateformat = "!%Y-%m-%d %H:%M:%S"
+local lasttime = nil
+local lastdate = nil
function os.fulltime(t,default)
- t = tonumber(t) or 0
+ t = t and tonumber(t) or 0
if t > 0 then
-- valid time
elseif default then
return default
else
- t = nil
+ t = time()
end
- return format(timeformat,date(dateformat,t))
+ if t ~= lasttime then
+ lasttime = t
+ lastdate = format(timeformat,date(dateformat))
+ end
+ return lastdate
end
local dateformat = "%Y-%m-%d %H:%M:%S"
+local lasttime = nil
+local lastdate = nil
function os.localtime(t,default)
- t = tonumber(t) or 0
+ t = t and tonumber(t) or 0
if t > 0 then
-- valid time
elseif default then
return default
else
- t = nil
+ t = time()
+ end
+ if t ~= lasttime then
+ lasttime = t
+ lastdate = date(dateformat,t)
end
- return date(dateformat,t)
+ return lastdate
end
function os.converttime(t,default)