X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/de5931c65f3f8a7138a412fcdfa8fce830807679..3f9a35944dbf63de85654d45120ab4291837ef9c:/.config/awesome/modules/luatz/examples/os_date.lua?ds=sidebyside diff --git a/.config/awesome/modules/luatz/examples/os_date.lua b/.config/awesome/modules/luatz/examples/os_date.lua new file mode 100644 index 0000000..ad254ce --- /dev/null +++ b/.config/awesome/modules/luatz/examples/os_date.lua @@ -0,0 +1,25 @@ +--[[ +Re-implementation of `os.date` from the standard lua library +]] + +local gettime = require "luatz.gettime".gettime +local new_from_timestamp = require "luatz.timetable".new_from_timestamp +local get_tz = require "luatz.tzcache".get_tz + +local function os_date(format_string, timestamp) + format_string = format_string or "%c" + timestamp = timestamp or gettime() + if format_string:sub(1, 1) == "!" then -- UTC + format_string = format_string:sub(2) + else -- Localtime + timestamp = get_tz():localise(timestamp) + end + local tt = new_from_timestamp(timestamp) + if format_string == "*t" then + return tt + else + return tt:strftime(format_string) + end +end + +return os_date