textclock: Produce reproducible output (#2622)
When $SOURCE_DIRECTORY is set, we are most likely currently running the
examples test, i.e. generating images. These images end up in the
documentation.
To make the images reproducable, i.e. independent from the current time,
this commit makes the textclock honor $SOURCE_DATE_EPOCH if
$SOURCE_DIRECTORY is set.
See commit 9d7eaf02
for some more details.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
0b4a84ccf3
commit
5f2cdabc01
|
@ -17,6 +17,17 @@ local TimeZone = glib.TimeZone
|
||||||
|
|
||||||
local textclock = { mt = {} }
|
local textclock = { mt = {} }
|
||||||
|
|
||||||
|
local DateTime_new_now = DateTime.new_now
|
||||||
|
|
||||||
|
-- When $SOURCE_DATE_EPOCH and $SOURCE_DIRECTORY are both set, then this code is
|
||||||
|
-- most likely being run by the test runner. Ensure reproducible dates.
|
||||||
|
local source_date_epoch = tonumber(os.getenv("SOURCE_DATE_EPOCH"))
|
||||||
|
if source_date_epoch and os.getenv("SOURCE_DIRECTORY") then
|
||||||
|
DateTime_new_now = function()
|
||||||
|
return DateTime.new_from_unix_utc(source_date_epoch)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Set the clock's format
|
--- Set the clock's format
|
||||||
-- @property format
|
-- @property format
|
||||||
-- @tparam string format The new time format. This can contain pango markup
|
-- @tparam string format The new time format. This can contain pango markup
|
||||||
|
@ -87,7 +98,7 @@ local function new(format, refresh, tzid)
|
||||||
w._private.timezone = tzid and TimeZone.new(tzid)
|
w._private.timezone = tzid and TimeZone.new(tzid)
|
||||||
|
|
||||||
function w._private.textclock_update_cb()
|
function w._private.textclock_update_cb()
|
||||||
local str = DateTime.new_now(w._private.timezone or TimeZone.new_local()):format(w._private.format)
|
local str = DateTime_new_now(w._private.timezone or TimeZone.new_local()):format(w._private.format)
|
||||||
if str == nil then
|
if str == nil then
|
||||||
require("gears.debug").print_warning("textclock: "
|
require("gears.debug").print_warning("textclock: "
|
||||||
.. "g_date_time_format() failed for format "
|
.. "g_date_time_format() failed for format "
|
||||||
|
|
Loading…
Reference in New Issue