]> git.madduck.net Git - etc/awesome.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

examples/os_date: Initial commit
authordaurnimator <quae@daurnimator.com>
Mon, 18 Aug 2014 18:39:08 +0000 (14:39 -0400)
committerdaurnimator <quae@daurnimator.com>
Mon, 18 Aug 2014 18:39:08 +0000 (14:39 -0400)
examples/os_date.lua [new file with mode: 0644]

diff --git a/examples/os_date.lua b/examples/os_date.lua
new file mode 100644 (file)
index 0000000..0164780
--- /dev/null
@@ -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 ):normalise ( )
+       if format_string == "*t" then
+               return tt
+       else
+               return tt:strftime ( format_string )
+       end
+end
+
+return os_date