]> git.madduck.net Git - etc/awesome.git/blob - luatz/tzcache.lua

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:

Document tzinfo
[etc/awesome.git] / luatz / tzcache.lua
1 local read_tzfile = require "luatz.tzfile".read_tzfile
2
3 local tz_cache = { }
4
5 local function name_to_zoneinfo_path ( name )
6         if name then
7                 return "/usr/share/zoneinfo/" .. name
8         else
9                 return "/etc/localtime"
10         end
11 end
12
13 local function clear_tz_cache ( name )
14         tz_cache [ name_to_zoneinfo_path ( name ) ] = nil
15 end
16
17 local function get_tz ( name )
18         local path = name_to_zoneinfo_path ( name )
19         -- TODO: stat path
20         local tzinfo = tz_cache [ path ]
21         if tzinfo == nil then
22                 tzinfo = read_tzfile ( path )
23                 tz_cache [ path ] = tzinfo
24         end
25         return tzinfo
26 end
27
28 return {
29         get_tz = get_tz ;
30         clear_tz_cache = clear_tz_cache ;
31 }