summaryrefslogtreecommitdiff
path: root/pkgs/astal/src/lib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/astal/src/lib.lua')
-rw-r--r--pkgs/astal/src/lib.lua23
1 files changed, 20 insertions, 3 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,
}