]> 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:

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