date: turn time widget argument into an offset

The os.time() call should not be passed as an argument it self,
because of a chance it will be stored internally and so we would
always get the same time. Instead we can pass time offsets in seconds,
i.e. to go 6 hours forward we can use the widget argument 21600, to go
6 hours back we use -21600 instead.
This commit is contained in:
Adrian C. (anrxc) 2010-10-04 22:42:31 +02:00
parent c6085eef06
commit e51d8ac39e
2 changed files with 9 additions and 5 deletions

7
README
View File

@ -266,9 +266,10 @@ vicious.widgets.weather
vicious.widgets.date
- provides access to os.date, with optional time formatting provided
as the format string
- takes optional time as an argument, for example to calculate
time-zone differences, otherwise it formats the current time
as the format string - using regular date sequences
- takes optional time offset, in seconds, as an argument for example
to calculate time zone differences, otherwise current time is
formatted
- returns the output of os.date(), formatted by provided sequences

View File

@ -5,8 +5,11 @@
---------------------------------------------------
-- {{{ Grab environment
local os = { date = os.date }
local setmetatable = setmetatable
local os = {
date = os.date,
time = os.time
}
-- }}}
@ -16,7 +19,7 @@ module("vicious.widgets.date")
-- {{{ Date widget type
local function worker(format, warg)
return os.date(format or nil, warg or nil)
return os.date(format or nil, warg and os.time()+warg or nil)
end
-- }}}