X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/72212b1e2c8784cf956862ef5ba63046fd9fba3d..0c40603e021b01bd61e4297dcdda6ab3eb8839d9:/luatz/init.lua diff --git a/luatz/init.lua b/luatz/init.lua index 3243f9d..8ab7cfc 100644 --- a/luatz/init.lua +++ b/luatz/init.lua @@ -1,13 +1,35 @@ -local get_tz = require "luatz.tzcache".get_tz +local _M = { + gettime = require "luatz.gettime" ; + parse = require "luatz.parse" ; + strftime = require "luatz.strftime" ; + timetable = require "luatz.timetable" ; + tzcache = require "luatz.tzcache" ; +} + +--- Top-level aliases for common functions + +_M.time = _M.gettime.gettime +_M.get_tz = _M.tzcache.get_tz -local function time_in ( tz , now ) - return get_tz ( tz ):localize ( now ) +--- Handy functions + +_M.time_in = function ( tz , now ) + return _M.get_tz ( tz ):localize ( now ) end -return { - get_tz = get_tz ; - time = require "luatz.gettime".gettime ; - time_in = time_in ; - parse = require "luatz.parse" ; - timetable = require "luatz.timetable" ; -} +--- C-like functions + +_M.gmtime = function ( ts ) + return _M.timetable.new_from_timestamp ( ts ):normalise ( ) +end + +_M.localtime = function ( ts ) + ts = _M.time_in ( nil , ts ) + return _M.gmtime ( ts ) +end + +_M.ctime = function ( ts ) + return _M.strftime.asctime ( _M.localtime ( ts ) ) +end + +return _M