]> git.madduck.net Git - etc/awesome.git/blob - src/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:

Move source to subdirectory
[etc/awesome.git] / src / 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         local tzinfo = tz_cache [ path ]
20         if tzinfo == nil then
21                 tzinfo = read_tzfile ( path )
22                 tz_cache [ path ] = tzinfo
23         end
24         return tzinfo
25 end
26
27 return {
28         get_tz = get_tz ;
29         clear_tz_cache = clear_tz_cache ;
30 }