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

luatz/strftime: Optimize asctime/bypass strftime
[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 == nil then
9                 return local_zoneinfo_path
10         elseif name:sub ( 1 , 1 ) == "/" then
11                 return name
12         else
13                 return base_zoneinfo_path .. name
14         end
15 end
16
17 local function clear_tz_cache ( name )
18         tz_cache [ name_to_zoneinfo_path ( name ) ] = nil
19 end
20
21 local function get_tz ( name )
22         local path = name_to_zoneinfo_path ( name )
23         -- TODO: stat path
24         local tzinfo = tz_cache [ path ]
25         if tzinfo == nil then
26                 tzinfo = read_tzfile ( path )
27                 tz_cache [ path ] = tzinfo
28         end
29         return tzinfo
30 end
31
32 return {
33         get_tz = get_tz ;
34         clear_tz_cache = clear_tz_cache ;
35 }