From 5f2cdabc0158f572c23f8b65040619f57fdd5f9a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 31 Jan 2019 20:34:41 +0100 Subject: [PATCH] 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 --- lib/wibox/widget/textclock.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/wibox/widget/textclock.lua b/lib/wibox/widget/textclock.lua index d4c5765e..4a7baa8f 100644 --- a/lib/wibox/widget/textclock.lua +++ b/lib/wibox/widget/textclock.lua @@ -17,6 +17,17 @@ local TimeZone = glib.TimeZone 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 -- @property format -- @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) 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 require("gears.debug").print_warning("textclock: " .. "g_date_time_format() failed for format "