diff options
author | Freya Murphy <freya@freyacat.org> | 2025-06-19 12:40:01 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-06-19 12:40:01 -0400 |
commit | 4b0fbc1feebfde058f2af2048fbb91ac15e6783f (patch) | |
tree | 26949163463859992429636d9200285c914a1d84 /pkgs/astal/src/lib.lua | |
parent | tlp (diff) | |
download | dotfiles-nix-4b0fbc1feebfde058f2af2048fbb91ac15e6783f.tar.gz dotfiles-nix-4b0fbc1feebfde058f2af2048fbb91ac15e6783f.tar.bz2 dotfiles-nix-4b0fbc1feebfde058f2af2048fbb91ac15e6783f.zip |
refactor time function in astal lib
Diffstat (limited to 'pkgs/astal/src/lib.lua')
-rw-r--r-- | pkgs/astal/src/lib.lua | 23 |
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, } |