From: daurnimator Date: Mon, 18 Aug 2014 15:56:44 +0000 (-0400) Subject: luatz/tzcache: Allow absolute paths X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/4f10d2a639cef8296fb8c096a238d3451164cc11 luatz/tzcache: Allow absolute paths --- diff --git a/doc/index.md b/doc/index.md index bb79641..09e7d7d 100644 --- a/doc/index.md +++ b/doc/index.md @@ -18,6 +18,7 @@ See `gettime` for more information. Returns a timezone object (see `tzinfo` documentation) for the given `timezone_name`. If `timezone_name` is `nil` then the local timezone is used. +If `timezone_name` is an absolute path, then that `tzinfo` file is used This uses the local [zoneinfo database](https://www.iana.org/time-zones); names are usually of the form `Country/Largest_City` e.g. "America/New_York". diff --git a/luatz/tzcache.lua b/luatz/tzcache.lua index 25a664d..98ced26 100644 --- a/luatz/tzcache.lua +++ b/luatz/tzcache.lua @@ -5,10 +5,12 @@ local local_zoneinfo_path = "/etc/localtime" local tz_cache = { } local function name_to_zoneinfo_path ( name ) - if name then - return base_zoneinfo_path .. name - else + if name == nil then return local_zoneinfo_path + elseif name:sub ( 1 , 1 ) == "/" then + return name + else + return base_zoneinfo_path .. name end end