X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/fc4bb72e16e19ae81d6f8b797186996c0ae46f33..c4d8a1bf5f96364056f744881037ca00b0465824:/luatz/tzcache.lua diff --git a/luatz/tzcache.lua b/luatz/tzcache.lua index 25a664d..ae32dce 100644 --- a/luatz/tzcache.lua +++ b/luatz/tzcache.lua @@ -2,32 +2,34 @@ local read_tzfile = require "luatz.tzfile".read_tzfile local base_zoneinfo_path = "/usr/share/zoneinfo/" local local_zoneinfo_path = "/etc/localtime" -local tz_cache = { } +local tz_cache = {} -local function name_to_zoneinfo_path ( name ) - if name then - return base_zoneinfo_path .. name - else +local function name_to_zoneinfo_path(name) + if name == nil then return local_zoneinfo_path + elseif name:sub(1, 1) == "/" then + return name + else + return base_zoneinfo_path .. name end end -local function clear_tz_cache ( name ) - tz_cache [ name_to_zoneinfo_path ( name ) ] = nil +local function clear_tz_cache(name) + tz_cache[name_to_zoneinfo_path(name)] = nil end -local function get_tz ( name ) - local path = name_to_zoneinfo_path ( name ) +local function get_tz(name) + local path = name_to_zoneinfo_path(name) -- TODO: stat path - local tzinfo = tz_cache [ path ] + local tzinfo = tz_cache[path] if tzinfo == nil then - tzinfo = read_tzfile ( path ) - tz_cache [ path ] = tzinfo + tzinfo = read_tzfile(path) + tz_cache[path] = tzinfo end return tzinfo end return { - get_tz = get_tz ; - clear_tz_cache = clear_tz_cache ; + get_tz = get_tz; + clear_tz_cache = clear_tz_cache; }