Add timezone option for textclock widget (#1743)
Adds a third parameter "timezone" to the textclock widget that is optional. Defaults to local timezone if nil. Signed-off-by: Matt Harrison <matt@harrison.us.com>
This commit is contained in:
parent
993ffef666
commit
ddf9689767
|
@ -10,7 +10,9 @@ local setmetatable = setmetatable
|
||||||
local os = os
|
local os = os
|
||||||
local textbox = require("wibox.widget.textbox")
|
local textbox = require("wibox.widget.textbox")
|
||||||
local timer = require("gears.timer")
|
local timer = require("gears.timer")
|
||||||
local DateTime = require("lgi").GLib.DateTime
|
local glib = require("lgi").GLib
|
||||||
|
local DateTime = glib.DateTime
|
||||||
|
local TimeZone = glib.TimeZone
|
||||||
|
|
||||||
local textclock = { mt = {} }
|
local textclock = { mt = {} }
|
||||||
|
|
||||||
|
@ -24,16 +26,20 @@ end
|
||||||
--
|
--
|
||||||
-- @tparam[opt=" %a %b %d, %H:%M "] string format The time format.
|
-- @tparam[opt=" %a %b %d, %H:%M "] string format The time format.
|
||||||
-- @tparam[opt=60] number timeout How often update the time (in seconds).
|
-- @tparam[opt=60] number timeout How often update the time (in seconds).
|
||||||
|
-- @tparam[opt=local timezone] string timezone The timezone to use,
|
||||||
|
-- e.g. "Z" for UTC, "±hh:mm" or "Europe/Amsterdam". See
|
||||||
|
-- https://developer.gnome.org/glib/stable/glib-GTimeZone.html#g-time-zone-new.
|
||||||
-- @treturn table A textbox widget.
|
-- @treturn table A textbox widget.
|
||||||
-- @function wibox.widget.textclock
|
-- @function wibox.widget.textclock
|
||||||
function textclock.new(format, timeout)
|
function textclock.new(format, timeout, timezone)
|
||||||
format = format or " %a %b %d, %H:%M "
|
format = format or " %a %b %d, %H:%M "
|
||||||
timeout = timeout or 60
|
timeout = timeout or 60
|
||||||
|
timezone = timezone and TimeZone.new(timezone) or TimeZone.new_local()
|
||||||
|
|
||||||
local w = textbox()
|
local w = textbox()
|
||||||
local t
|
local t
|
||||||
function w._private.textclock_update_cb()
|
function w._private.textclock_update_cb()
|
||||||
w:set_markup(DateTime.new_now_local():format(format))
|
w:set_markup(DateTime.new_now(timezone):format(format))
|
||||||
t.timeout = calc_timeout(timeout)
|
t.timeout = calc_timeout(timeout)
|
||||||
t:again()
|
t:again()
|
||||||
return true -- Continue the timer
|
return true -- Continue the timer
|
||||||
|
|
Loading…
Reference in New Issue