From 1fb948b72b60999c61027ddb76d294c954a95f14 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Tue, 13 Feb 2018 11:46:40 +1300 Subject: [PATCH] Globetrotter clock display --- .config/awesome/rc.lua | 46 +++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index 99b72e9..861013b 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -15,6 +15,7 @@ local lain = require("lain") local dkjson = require("lain.util").dkjson local math = require("math") local freedesktop = require("freedesktop") +local luatz = require("luatz") -- }}} -- {{{ Error handling @@ -200,7 +201,24 @@ menubar.utils.terminal = terminal -- Set the terminal for applications that requ local spacer = wibox.widget.textbox() spacer:set_text(' | ') -- Create a textclock widget -mytextclock = wibox.widget.textclock("%a %d %b %H:%M:%S", 1) +clocks = { wibox.widget.textclock("%a %d %b %H:%M:%S", 1) } + +ZONES = { + ["NZ"] = "Pacific/Auckland", + ["DE"] = "Europe/Berlin" +} + +now = luatz.time_in(nil) +for c, tz in sorted_pairs(ZONES) do + t = luatz.time_in(tz) + print (c) + print (os.difftime(t, now)) + if math.abs(os.difftime(t, now)) > 10 then + local widget = wibox.widget.textclock(c .. ": %H:%M (%a)", 60, tz) + table.insert(clocks, spacer) + table.insert(clocks, widget) + end +end -- Create a wibox for each screen and add it mywibox = {} @@ -336,17 +354,21 @@ awful.screen.connect_for_each_screen(function(s) mypromptbox[s], }, mytasklist[s], -- Middle widget - { -- Right widgets - layout = wibox.layout.fixed.horizontal, - mykeyboardlayout, - wibox.widget.systray(), - btc_widget, - spacer, - lain_bat.widget, - spacer, - mytextclock, - mylayoutbox[s], - }, + awful.util.table.join( -- Right widgets + { + layout = wibox.layout.fixed.horizontal, + mykeyboardlayout, + wibox.widget.systray(), + btc_widget, + spacer, + lain_bat.widget, + spacer, + }, + clocks, + { + mylayoutbox[s], + } + ), } end) -- }}} -- 2.39.5