summaryrefslogtreecommitdiff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/astal/src/lib.lua23
-rw-r--r--pkgs/astal/src/widget/bar/date.lua5
-rw-r--r--pkgs/astal/src/widget/deck/notifications.lua2
3 files changed, 23 insertions, 7 deletions
diff --git a/pkgs/astal/src/lib.lua b/pkgs/astal/src/lib.lua
index 992c0af..71a6c65 100644
--- a/pkgs/astal/src/lib.lua
+++ b/pkgs/astal/src/lib.lua
@@ -127,10 +127,27 @@ lib = {
return Astal.Icon.lookup_icon(icon) ~= nil
end,
+ --- applies one object onto another
+ apply = function(l, r)
+ for k,v in pairs(r) do
+ l[k] = v
+ end
+ return l
+ end,
+
+ --- returns current unix epoch
+ unix = function()
+ return os.time(os.date("!*t"))
+ end,
+
--- formats a time
- time = function(time, format)
- format = format or "%H:%M"
- return GLib.DateTime.new_from_unix_local(time):format(format)
+ time = function(t)
+ -- default args
+ t = lib.apply({
+ time = lib.unix(),
+ format = "%H:%M"
+ }, t or {})
+ return GLib.DateTime.new_from_unix_local(t.time):format(t.format)
end,
}
diff --git a/pkgs/astal/src/widget/bar/date.lua b/pkgs/astal/src/widget/bar/date.lua
index b64d8bb..7afa20e 100644
--- a/pkgs/astal/src/widget/bar/date.lua
+++ b/pkgs/astal/src/widget/bar/date.lua
@@ -1,12 +1,11 @@
local astal = require("astal")
local Widget = require("astal.gtk3.widget")
local Variable = astal.Variable
-local GLib = astal.require("GLib")
+local lib = require("lib")
-local format = "%Y-%m-%d %a %H:%M:%S"
local date = Variable(""):poll(
1000, function()
- return GLib.DateTime.new_now_local():format(format)
+ return lib.time({ format = "%Y-%m-%d %a %H:%M:%S" })
end
);
diff --git a/pkgs/astal/src/widget/deck/notifications.lua b/pkgs/astal/src/widget/deck/notifications.lua
index e40a815..63740ab 100644
--- a/pkgs/astal/src/widget/deck/notifications.lua
+++ b/pkgs/astal/src/widget/deck/notifications.lua
@@ -53,7 +53,7 @@ function Header(notif)
class_name = "time",
hexpand = true,
halign = "END",
- label = lib.time(notif.time),
+ label = lib.time({ time = notif.time }),
}),
Widget.Button({
on_clicked = function() delete(notif.id) end,